refactoring and more tests