Fix bug in QueryAPI