done refactoring, all tests passing