I've attached a preliminary patch to fix this bug. Mark