Updated query handling

Signed-off-by: Tom Wright <tom@inflatablecookie.com>