refactoring for testability