refactoring function content for unit test