refactoring and unit test