fix bugs in query functions .