Refactoring for unit testing