added some tests
some refactoring