some refactoring and additional tests