refactoring and adding new tests

refactoring and adding new tests