removing unneeded SQL queries