bug fixes from unit tests