Various query fixes.