Optimize queries

Started with no optimization.