refactoring and adding more tests