Refactored to use a shared query-rendering routine.