Some more query optimizations