refactor for dependency injection