some refactoring and additional tests
some more refactoring