fixed problems with logical operators in query