Completely restructured query system

…And fixed a bug.
Deleted a line