attempting to optimize some of the mysql queries