Refactoring and test passing