Added ability to specify a queryFunction that returns a query object