Refactoring for testability