re-jigged server-side query-handling code