refactoring and new tests