Refactoring code; passing all tests