bug fix in query