Fixed a bug for queries