fixing bugs in querry