refactor for testability