Refactored code and unit-test