Refactoring for unit testability