fix a bug in the query function