Optimized some SQL queries to reduce server load