refactoring, passing the tests