Refactoring and test