small refactor and added tests