Cleaned up SQL queries along with removing old code