refactoring and adding a test