refactoring, adding tests