refactor for testability/sanity