Bug fixes so it passes all tests