Refactor for testability