Clean up some code with dependency injection.