Increase performance by reducing number of SQL queries