Refactored ServiceQueryImpl to enhance testability.