Bug fixes to ensure all tests pass