More refactoring to make it easier to do dependency injection