refactoring over, all tests passing