Small fixes on a fixes
Changed use of JFactory::getDBO() method to JFactory::getDbo()
Changed use of variable name $db->setQuery((string) $query) to $db->setQuery($query)
Fixed some general syntax and converted a few string sql statements to query objects