Query enhancements and bugs fixes.