refactoring and testing