completed refactoring, tests work. Still to be tested