Query and Scan support and other fixes.

Plus two very minor fixes.