Refactoring for dependency injection