fix bugs for query