more refactoring for more testability