refactoring, added tests