bug fixes exposed by tests