fixed the query bug