refactorings, added tests