Minor bug fix in query