Refactoring and unit-test