various query related fixes.