reorganized for separation of concerns/testability