refactoring + added tests