Updated query parsing code. Vastly simplified since the front end does a
lot more work now.