optimized queries fix