refactored to include dependency injection