Made some changes to the way the db class generates SQL queries