More refactoring for testability