Refactor dependency injection