Optimize several queries