refactoring, tests work