some refactorings
added some tests and did some refactoring