Fix query bugs.