bug fixes to make all tests pass