Fix bool conditions in query