refactoring and adding new tests
more refactoring