refactoring, tests added