Reimplement query language.
Fixing tests for new query system.