fixed the query issues