Fix query bug