refactoring and additional tests