fix bugs; all tests pass