refactored for testability