Fix for non-equal-operator queries

Query was broken for operators other than '='. Fix and tests included.