Factor out queryExecute