query bug fix