Refactoring and unit testing