refactored for better isolation of dependency injection