refactored, tests are green