restructure for testability