Optimized some queries