Updated to improve dependency injection.