Merge remote-tracking branch 'upstream/develop' into develop-core-security
diff --git a/application/config/config.php b/application/config/config.php
index bb35324..17b854b 100644
--- a/application/config/config.php
+++ b/application/config/config.php
@@ -326,12 +326,14 @@
 | 'csrf_token_name' = The token name
 | 'csrf_cookie_name' = The cookie name
 | 'csrf_expire' = The number in seconds the token should expire.
+| 'csrf_regenerate' = Regenerate token on every submission
 | 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
 */
 $config['csrf_protection'] = FALSE;
 $config['csrf_token_name'] = 'csrf_test_name';
 $config['csrf_cookie_name'] = 'csrf_cookie_name';
 $config['csrf_expire'] = 7200;
+$config['csrf_regenerate'] = TRUE;
 $config['csrf_exclude_uris'] = array();
 
 /*
diff --git a/index.php b/index.php
index 4ae1cee..1712a7d 100644
--- a/index.php
+++ b/index.php
@@ -5,9 +5,9 @@
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -41,7 +41,6 @@
  *     production
  *
  * NOTE: If you change these, also change the error_reporting() code below
- *
  */
 	define('ENVIRONMENT', 'development');
 /*
@@ -60,12 +59,10 @@
 		case 'development':
 			error_reporting(-1);
 		break;
-	
 		case 'testing':
 		case 'production':
 			error_reporting(0);
 		break;
-
 		default:
 			exit('The application environment is not set correctly.');
 	}
@@ -79,7 +76,6 @@
  * This variable must contain the name of your "system" folder.
  * Include the path if the folder is not in the same  directory
  * as this file.
- *
  */
 	$system_path = 'system';
 
@@ -90,30 +86,28 @@
  *
  * If you want this front controller to use a different "application"
  * folder then the default one you can set its name here. The folder
- * can also be renamed or relocated anywhere on your server.  If
+ * can also be renamed or relocated anywhere on your server. If
  * you do, use a full server path. For more info please see the user guide:
  * http://codeigniter.com/user_guide/general/managing_apps.html
  *
  * NO TRAILING SLASH!
- *
  */
 	$application_folder = 'application';
-		
+
 /*
  *---------------------------------------------------------------
  * VIEW FOLDER NAME
  *---------------------------------------------------------------
- * 
- * If you want to move the view folder out of the application 
+ *
+ * If you want to move the view folder out of the application
  * folder set the path to the folder here. The folder can be renamed
- * and relocated anywhere on your server. If blank, it will default 
- * to the standard location inside your application folder.  If you 
- * do move this, use the full server path to this folder 
+ * and relocated anywhere on your server. If blank, it will default
+ * to the standard location inside your application folder. If you
+ * do move this, use the full server path to this folder.
  *
  * NO TRAILING SLASH!
- *
  */
-	$view_folder = '';	
+	$view_folder = '';
 
 
 /*
@@ -123,18 +117,17 @@
  *
  * Normally you will set your default controller in the routes.php file.
  * You can, however, force a custom routing by hard-coding a
- * specific controller class/function here.  For most applications, you
+ * specific controller class/function here. For most applications, you
  * WILL NOT set your routing here, but it's an option for those
  * special instances where you might want to override the standard
  * routing in a specific front controller that shares a common CI installation.
  *
- * IMPORTANT:  If you set the routing here, NO OTHER controller will be
+ * IMPORTANT: If you set the routing here, NO OTHER controller will be
  * callable. In essence, this preference limits your application to ONE
- * specific controller.  Leave the function name blank if you need
+ * specific controller. Leave the function name blank if you need
  * to call functions dynamically via the URI.
  *
  * Un-comment the $routing array below to use this feature
- *
  */
 	// The directory name, relative to the "controllers" folder.  Leave blank
 	// if your controller is not in a sub-folder within the "controllers" folder
@@ -160,7 +153,6 @@
  * config values.
  *
  * Un-comment the $assign_to_config array below to use this feature
- *
  */
 	// $assign_to_config['name_of_config_item'] = 'value of config item';
 
@@ -193,7 +185,7 @@
 	// Is the system path correct?
 	if ( ! is_dir($system_path))
 	{
-		exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
+		exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME));
 	}
 
 /*
@@ -209,7 +201,7 @@
 	define('EXT', '.php');
 
 	// Path to the system folder
-	define('BASEPATH', str_replace("\\", "/", $system_path));
+	define('BASEPATH', str_replace('\\', '/', $system_path));
 
 	// Path to the front controller (this file)
 	define('FCPATH', str_replace(SELF, '', __FILE__));
@@ -217,7 +209,6 @@
 	// Name of the "system folder"
 	define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
 
-
 	// The path to the "application" folder
 	if (is_dir($application_folder))
 	{
@@ -227,27 +218,26 @@
 	{
 		if ( ! is_dir(BASEPATH.$application_folder.'/'))
 		{
-			exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
+			exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
 		}
 
 		define('APPPATH', BASEPATH.$application_folder.'/');
 	}
-	
+
 	// The path to the "views" folder
-	if (is_dir($view_folder)) 
+	if (is_dir($view_folder))
 	{
 		define ('VIEWPATH', $view_folder .'/');
 	}
-	else 
+	else
 	{
 		if ( ! is_dir(APPPATH.'views/'))
 		{
-			exit("Your view folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
+			exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
 		}
-				
-		define ('VIEWPATH', APPPATH.'views/' );	
+
+		define ('VIEWPATH', APPPATH.'views/' );
 	}
-	
 
 /*
  * --------------------------------------------------------------------
@@ -255,9 +245,8 @@
  * --------------------------------------------------------------------
  *
  * And away we go...
- *
  */
 require_once BASEPATH.'core/CodeIgniter.php';
 
 /* End of file index.php */
-/* Location: ./index.php */
\ No newline at end of file
+/* Location: ./index.php */
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php
index da246c9..f4dfd3d 100755
--- a/system/core/Benchmark.php
+++ b/system/core/Benchmark.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -15,7 +15,7 @@
  * If you did not receive a copy of the license and are unable to obtain it
  * through the world wide web, please send an email to
  * licensing@ellislab.com so we can send you a copy immediately.
- * 
+ *
  * @package		CodeIgniter
  * @author		EllisLab Dev Team
  * @copyright	Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
@@ -46,7 +46,7 @@
 	 *
 	 * @var array
 	 */
-	var $marker = array();
+	public $marker = array();
 
 	// --------------------------------------------------------------------
 
@@ -56,11 +56,10 @@
 	 * Multiple calls to this function can be made so that several
 	 * execution points can be timed
 	 *
-	 * @access	public
 	 * @param	string	$name	name of the marker
 	 * @return	void
 	 */
-	function mark($name)
+	public function mark($name)
 	{
 		$this->marker[$name] = microtime();
 	}
@@ -75,13 +74,12 @@
 	 * execution time to be shown in a template. The output class will
 	 * swap the real value for this variable.
 	 *
-	 * @access	public
 	 * @param	string	a particular marked point
 	 * @param	string	a particular marked point
 	 * @param	integer	the number of decimal places
 	 * @return	mixed
 	 */
-	function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
+	public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
 	{
 		if ($point1 == '')
 		{
@@ -114,17 +112,14 @@
 	 * without the memory being calculated until the end.
 	 * The output class will swap the real value for this variable.
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function memory_usage()
+	public function memory_usage()
 	{
 		return '{memory_usage}';
 	}
 
 }
 
-// END CI_Benchmark class
-
 /* End of file Benchmark.php */
-/* Location: ./system/core/Benchmark.php */
\ No newline at end of file
+/* Location: ./system/core/Benchmark.php */
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 5152073..cb5d439 100755
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -59,7 +59,7 @@
  *  Load the framework constants
  * ------------------------------------------------------
  */
-	if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
+	if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
 	{
 		require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
 	}
@@ -91,12 +91,12 @@
  * "libraries" folder. Since CI allows config items to be
  * overriden via data set in the main index. php file,
  * before proceeding we need to know if a subclass_prefix
- * override exists.  If so, we will set this value now,
+ * override exists. If so, we will set this value now,
  * before any classes are loaded
  * Note: Since the config file data is cached it doesn't
  * hurt to load it here.
  */
-	if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
+	if (isset($assign_to_config['subclass_prefix']) && $assign_to_config['subclass_prefix'] != '')
 	{
 		get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
 	}
@@ -106,13 +106,10 @@
  *  Set a liberal script execution time limit
  * ------------------------------------------------------
  */
-	if (function_exists("set_time_limit") AND @ini_get("safe_mode") == 0)
+	if (function_exists('set_time_limit') && @ini_get('safe_mode') == 0
+		&& php_sapi_name() !== 'cli') // Do not override the Time Limit value if running from Command Line
 	{
-		// Do not override the Time Limit value if running from Command Line
-		if(php_sapi_name() != 'cli')
-		{
-			@set_time_limit(300);
-		}
+		@set_time_limit(300);
 	}
 
 /*
@@ -162,7 +159,6 @@
  * after the Config class is instantiated.
  *
  */
-
 	$UNI =& load_class('Utf8', 'core');
 
 /*
@@ -195,15 +191,13 @@
 
 /*
  * ------------------------------------------------------
- *	Is there a valid cache file?  If so, we're done...
+ *	Is there a valid cache file? If so, we're done...
  * ------------------------------------------------------
  */
-	if ($EXT->_call_hook('cache_override') === FALSE)
+	if ($EXT->_call_hook('cache_override') === FALSE
+		&& $OUT->_display_cache($CFG, $URI) == TRUE)
 	{
-		if ($OUT->_display_cache($CFG, $URI) == TRUE)
-		{
-			exit;
-		}
+		exit;
 	}
 
 /*
@@ -273,13 +267,13 @@
 	$method = $RTR->fetch_method();
 
 	if ( ! class_exists($class)
-		OR strncmp($method, '_', 1) == 0
+		OR strpos($method, '_', 1) === 0
 		OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
 		)
 	{
 		if ( ! empty($RTR->routes['404_override']))
 		{
-			$x = explode('/', $RTR->routes['404_override']);
+			$x = explode('/', $RTR->routes['404_override'], 2);
 			$class = $x[0];
 			$method = (isset($x[1]) ? $x[1] : 'index');
 			if ( ! class_exists($class))
@@ -341,7 +335,7 @@
 			// Check and see if we are using a 404 override and use it.
 			if ( ! empty($RTR->routes['404_override']))
 			{
-				$x = explode('/', $RTR->routes['404_override']);
+				$x = explode('/', $RTR->routes['404_override'], 2);
 				$class = $x[0];
 				$method = (isset($x[1]) ? $x[1] : 'index');
 				if ( ! class_exists($class))
@@ -367,7 +361,6 @@
 		call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
 	}
 
-
 	// Mark a benchmark end point
 	$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
 
@@ -400,11 +393,10 @@
  *  Close the DB connection if one exists
  * ------------------------------------------------------
  */
-	if (class_exists('CI_DB') AND isset($CI->db))
+	if (class_exists('CI_DB') && isset($CI->db))
 	{
 		$CI->db->close();
 	}
 
-
 /* End of file CodeIgniter.php */
-/* Location: ./system/core/CodeIgniter.php */
\ No newline at end of file
+/* Location: ./system/core/CodeIgniter.php */
diff --git a/system/core/Common.php b/system/core/Common.php
index f42bb64..6ef2296 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -73,10 +73,10 @@
  * Tests for file writability
  *
  * is_writable() returns TRUE on Windows servers when you really can't write to
- * the file, based on the read-only attribute.  is_writable() is also unreliable
+ * the file, based on the read-only attribute. is_writable() is also unreliable
  * on Unix servers if safe_mode is on.
  *
- * @access	private
+ * @access	public
  * @return	void
  */
 if ( ! function_exists('is_really_writable'))
@@ -84,17 +84,17 @@
 	function is_really_writable($file)
 	{
 		// If we're on a Unix server with safe_mode off we call is_writable
-		if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
+		if (DIRECTORY_SEPARATOR === '/' AND @ini_get('safe_mode') == FALSE)
 		{
 			return is_writable($file);
 		}
 
-		// For windows servers and safe_mode "on" installations we'll actually
-		// write a file then read it.  Bah...
+		/* For Windows servers and safe_mode "on" installations we'll actually
+		 * write a file then read it. Bah...
+		 */
 		if (is_dir($file))
 		{
 			$file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100));
-
 			if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
 			{
 				return FALSE;
@@ -136,7 +136,7 @@
 	{
 		static $_classes = array();
 
-		// Does the class exist?  If so, we're done...
+		// Does the class exist? If so, we're done...
 		if (isset($_classes[$class]))
 		{
 			return $_classes[$class];
@@ -161,7 +161,7 @@
 			}
 		}
 
-		// Is the request a class extension?  If so we load it too
+		// Is the request a class extension? If so we load it too
 		if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
 		{
 			$name = config_item('subclass_prefix').$class;
@@ -235,7 +235,7 @@
 		}
 
 		// Is the config file in the environment folder?
-		if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+		if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT..'/config.php'))
 		{
 			$file_path = APPPATH.'config/config.php';
 		}
@@ -387,47 +387,47 @@
 	function set_status_header($code = 200, $text = '')
 	{
 		$stati = array(
-							200	=> 'OK',
-							201	=> 'Created',
-							202	=> 'Accepted',
-							203	=> 'Non-Authoritative Information',
-							204	=> 'No Content',
-							205	=> 'Reset Content',
-							206	=> 'Partial Content',
+					200	=> 'OK',
+					201	=> 'Created',
+					202	=> 'Accepted',
+					203	=> 'Non-Authoritative Information',
+					204	=> 'No Content',
+					205	=> 'Reset Content',
+					206	=> 'Partial Content',
 
-							300	=> 'Multiple Choices',
-							301	=> 'Moved Permanently',
-							302	=> 'Found',
-							304	=> 'Not Modified',
-							305	=> 'Use Proxy',
-							307	=> 'Temporary Redirect',
+					300	=> 'Multiple Choices',
+					301	=> 'Moved Permanently',
+					302	=> 'Found',
+					304	=> 'Not Modified',
+					305	=> 'Use Proxy',
+					307	=> 'Temporary Redirect',
 
-							400	=> 'Bad Request',
-							401	=> 'Unauthorized',
-							403	=> 'Forbidden',
-							404	=> 'Not Found',
-							405	=> 'Method Not Allowed',
-							406	=> 'Not Acceptable',
-							407	=> 'Proxy Authentication Required',
-							408	=> 'Request Timeout',
-							409	=> 'Conflict',
-							410	=> 'Gone',
-							411	=> 'Length Required',
-							412	=> 'Precondition Failed',
-							413	=> 'Request Entity Too Large',
-							414	=> 'Request-URI Too Long',
-							415	=> 'Unsupported Media Type',
-							416	=> 'Requested Range Not Satisfiable',
-							417	=> 'Expectation Failed',
-							422	=> 'Unprocessable Entity',
+					400	=> 'Bad Request',
+					401	=> 'Unauthorized',
+					403	=> 'Forbidden',
+					404	=> 'Not Found',
+					405	=> 'Method Not Allowed',
+					406	=> 'Not Acceptable',
+					407	=> 'Proxy Authentication Required',
+					408	=> 'Request Timeout',
+					409	=> 'Conflict',
+					410	=> 'Gone',
+					411	=> 'Length Required',
+					412	=> 'Precondition Failed',
+					413	=> 'Request Entity Too Large',
+					414	=> 'Request-URI Too Long',
+					415	=> 'Unsupported Media Type',
+					416	=> 'Requested Range Not Satisfiable',
+					417	=> 'Expectation Failed',
+					422	=> 'Unprocessable Entity',
 
-							500	=> 'Internal Server Error',
-							501	=> 'Not Implemented',
-							502	=> 'Bad Gateway',
-							503	=> 'Service Unavailable',
-							504	=> 'Gateway Timeout',
-							505	=> 'HTTP Version Not Supported'
-						);
+					500	=> 'Internal Server Error',
+					501	=> 'Not Implemented',
+					502	=> 'Bad Gateway',
+					503	=> 'Service Unavailable',
+					504	=> 'Gateway Timeout',
+					505	=> 'HTTP Version Not Supported'
+			);
 
 		if ($code == '' OR ! is_numeric($code))
 		{
@@ -441,12 +441,12 @@
 
 		if ($text == '')
 		{
-			show_error('No status text available.  Please check your status code number or supply your own message text.', 500);
+			show_error('No status text available. Please check your status code number or supply your own message text.', 500);
 		}
 
 		$server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
 
-		if (substr(php_sapi_name(), 0, 3) == 'cgi')
+		if (strpos(php_sapi_name(), 'cgi') === 0)
 		{
 			header("Status: {$code} {$text}", TRUE);
 		}
@@ -527,16 +527,15 @@
 	function remove_invisible_characters($str, $url_encoded = TRUE)
 	{
 		$non_displayables = array();
-		
-		// every control character except newline (dec 10)
-		// carriage return (dec 13), and horizontal tab (dec 09)
-		
+
+		// every control character except newline (dec 10),
+		// carriage return (dec 13) and horizontal tab (dec 09)
 		if ($url_encoded)
 		{
 			$non_displayables[] = '/%0[0-8bcef]/';	// url encoded 00-08, 11, 12, 14, 15
 			$non_displayables[] = '/%1[0-9a-f]/';	// url encoded 16-31
 		}
-		
+
 		$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S';	// 00-08, 11, 12, 14-31, 127
 
 		do
@@ -574,4 +573,4 @@
 }
 
 /* End of file Common.php */
-/* Location: ./system/core/Common.php */
\ No newline at end of file
+/* Location: ./system/core/Common.php */
diff --git a/system/core/Config.php b/system/core/Config.php
index 3e26354..6636911 100755
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -45,35 +45,35 @@
 	 *
 	 * @var array
 	 */
-	var $config = array();
+	public $config = array();
 	/**
 	 * List of all loaded config files
 	 *
 	 * @var array
 	 */
-	var $is_loaded = array();
+	public $is_loaded = array();
 	/**
-	 * List of paths to search when trying to load a config file
+	 * List of paths to search when trying to load a config file.
+	 * This must be public as it's used by the Loader class.
 	 *
 	 * @var array
 	 */
-	var $_config_paths = array(APPPATH);
+	public $_config_paths = array(APPPATH);
 
 	/**
 	 * Constructor
 	 *
 	 * Sets the $config data from the primary config.php file as a class variable
 	 *
-	 * @access   public
 	 * @param   string	the config file name
 	 * @param   boolean  if configuration values should be loaded into their own section
 	 * @param   boolean  true if errors should just return false, false if an error message should be displayed
 	 * @return  boolean  if the file was successfully loaded or not
 	 */
-	function __construct()
+	public function __construct()
 	{
 		$this->config =& get_config();
-		log_message('debug', "Config Class Initialized");
+		log_message('debug', 'Config Class Initialized');
 
 		// Set the base_url automatically if none was provided
 		if ($this->config['base_url'] == '')
@@ -81,10 +81,9 @@
 			if (isset($_SERVER['HTTP_HOST']))
 			{
 				$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
-				$base_url .= '://'. $_SERVER['HTTP_HOST'];
-				$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+				$base_url .= '://'. $_SERVER['HTTP_HOST']
+					. str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
 			}
-
 			else
 			{
 				$base_url = 'http://localhost/';
@@ -99,17 +98,15 @@
 	/**
 	 * Load Config File
 	 *
-	 * @access	public
 	 * @param	string	the config file name
-	 * @param   boolean  if configuration values should be loaded into their own section
-	 * @param   boolean  true if errors should just return false, false if an error message should be displayed
+	 * @param	boolean	if configuration values should be loaded into their own section
+	 * @param	boolean	true if errors should just return false, false if an error message should be displayed
 	 * @return	boolean	if the file was loaded correctly
 	 */
-	function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
+	public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
 	{
 		$file = ($file == '') ? 'config' : str_replace('.php', '', $file);
-		$found = FALSE;
-		$loaded = FALSE;
+		$found = $loaded = FALSE;
 
 		foreach ($this->_config_paths as $path)
 		{
@@ -192,39 +189,19 @@
 	 * Fetch a config file item
 	 *
 	 *
-	 * @access	public
 	 * @param	string	the config item name
 	 * @param	string	the index name
 	 * @param	bool
 	 * @return	string
 	 */
-	function item($item, $index = '')
+	public function item($item, $index = '')
 	{
 		if ($index == '')
 		{
-			if ( ! isset($this->config[$item]))
-			{
-				return FALSE;
-			}
-
-			$pref = $this->config[$item];
-		}
-		else
-		{
-			if ( ! isset($this->config[$index]))
-			{
-				return FALSE;
-			}
-
-			if ( ! isset($this->config[$index][$item]))
-			{
-				return FALSE;
-			}
-
-			$pref = $this->config[$index][$item];
+			return isset($this->config[$item]) ? $this->config[$item] : FALSE;
 		}
 
-		return $pref;
+		return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : FALSE;
 	}
 
 	// --------------------------------------------------------------------
@@ -232,18 +209,17 @@
 	/**
 	 * Fetch a config file item - adds slash after item (if item is not empty)
 	 *
-	 * @access	public
 	 * @param	string	the config item name
 	 * @param	bool
 	 * @return	string
 	 */
-	function slash_item($item)
+	public function slash_item($item)
 	{
 		if ( ! isset($this->config[$item]))
 		{
 			return FALSE;
 		}
-		if( trim($this->config[$item]) == '')
+		elseif (trim($this->config[$item]) == '')
 		{
 			return '';
 		}
@@ -257,11 +233,10 @@
 	 * Site URL
 	 * Returns base_url . index_page [. uri_string]
 	 *
-	 * @access	public
 	 * @param	string	the URI string
 	 * @return	string
 	 */
-	function site_url($uri = '')
+	public function site_url($uri = '')
 	{
 		if ($uri == '')
 		{
@@ -285,11 +260,10 @@
 	 * Base URL
 	 * Returns base_url [. uri_string]
 	 *
-	 * @access public
 	 * @param string $uri
 	 * @return string
 	 */
-	function base_url($uri = '')
+	public function base_url($uri = '')
 	{
 		return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
 	}
@@ -299,8 +273,7 @@
 	/**
 	 * Build URI string for use in Config::site_url() and Config::base_url()
 	 *
-	 * @access protected
-	 * @param  $uri
+	 * @param  mixed $uri
 	 * @return string
 	 */
 	protected function _uri_string($uri)
@@ -311,23 +284,21 @@
 			{
 				$uri = implode('/', $uri);
 			}
-			$uri = trim($uri, '/');
+			return trim($uri, '/');
 		}
-		else
+		elseif (is_array($uri))
 		{
-			if (is_array($uri))
+			$i = 0;
+			$str = '';
+			foreach ($uri as $key => $val)
 			{
-				$i = 0;
-				$str = '';
-				foreach ($uri as $key => $val)
-				{
-					$prefix = ($i == 0) ? '' : '&';
-					$str .= $prefix.$key.'='.$val;
-					$i++;
-				}
-				$uri = $str;
+				$prefix = ($i === 0) ? '' : '&';
+				$str .= $prefix.$key.'='.$val;
+				$i++;
 			}
+			return $str;
 		}
+
 		return $uri;
 	}
 
@@ -336,12 +307,11 @@
 	/**
 	 * System URL
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function system_url()
+	public function system_url()
 	{
-		$x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
+		$x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH));
 		return $this->slash_item('base_url').end($x).'/';
 	}
 
@@ -350,12 +320,11 @@
 	/**
 	 * Set a config file item
 	 *
-	 * @access	public
 	 * @param	string	the config item key
 	 * @param	string	the config item value
 	 * @return	void
 	 */
-	function set_item($item, $value)
+	public function set_item($item, $value)
 	{
 		$this->config[$item] = $value;
 	}
@@ -366,14 +335,13 @@
 	 * Assign to Config
 	 *
 	 * This function is called by the front controller (CodeIgniter.php)
-	 * after the Config class is instantiated.  It permits config items
+	 * after the Config class is instantiated. It permits config items
 	 * to be assigned or overriden by variables contained in the index.php file
 	 *
-	 * @access	private
 	 * @param	array
 	 * @return	void
 	 */
-	function _assign_to_config($items = array())
+	public function _assign_to_config($items = array())
 	{
 		if (is_array($items))
 		{
@@ -385,7 +353,5 @@
 	}
 }
 
-// END CI_Config class
-
 /* End of file Config.php */
 /* Location: ./system/core/Config.php */
diff --git a/system/core/Controller.php b/system/core/Controller.php
index 55b3ec2..0dc1317 100644
--- a/system/core/Controller.php
+++ b/system/core/Controller.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -43,13 +43,10 @@
 
 	private static $instance;
 
-	/**
-	 * Constructor
-	 */
 	public function __construct()
 	{
 		self::$instance =& $this;
-		
+
 		// Assign all the class objects that were instantiated by the
 		// bootstrap file (CodeIgniter.php) to local class variables
 		// so that CI can run as one big super object.
@@ -59,10 +56,8 @@
 		}
 
 		$this->load =& load_class('Loader', 'core');
-
 		$this->load->initialize();
-		
-		log_message('debug', "Controller Class Initialized");
+		log_message('debug', 'Controller Class Initialized');
 	}
 
 	public static function &get_instance()
@@ -70,7 +65,6 @@
 		return self::$instance;
 	}
 }
-// END Controller class
 
 /* End of file Controller.php */
-/* Location: ./system/core/Controller.php */
\ No newline at end of file
+/* Location: ./system/core/Controller.php */
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 3737f29..bf99012 100755
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -37,49 +37,44 @@
  * @link		http://codeigniter.com/user_guide/libraries/exceptions.html
  */
 class CI_Exceptions {
-	var $action;
-	var $severity;
-	var $message;
-	var $filename;
-	var $line;
+
+	public $action;
+	public $severity;
+	public $message;
+	public $filename;
+	public $line;
 
 	/**
 	 * Nesting level of the output buffering mechanism
 	 *
 	 * @var int
-	 * @access public
 	 */
-	var $ob_level;
+	public $ob_level;
 
 	/**
 	 * List if available error levels
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var $levels = array(
-						E_ERROR				=>	'Error',
-						E_WARNING			=>	'Warning',
-						E_PARSE				=>	'Parsing Error',
-						E_NOTICE			=>	'Notice',
-						E_CORE_ERROR		=>	'Core Error',
-						E_CORE_WARNING		=>	'Core Warning',
-						E_COMPILE_ERROR		=>	'Compile Error',
-						E_COMPILE_WARNING	=>	'Compile Warning',
-						E_USER_ERROR		=>	'User Error',
-						E_USER_WARNING		=>	'User Warning',
-						E_USER_NOTICE		=>	'User Notice',
-						E_STRICT			=>	'Runtime Notice'
-					);
+	public $levels = array(
+				E_ERROR			=>	'Error',
+				E_WARNING		=>	'Warning',
+				E_PARSE			=>	'Parsing Error',
+				E_NOTICE		=>	'Notice',
+				E_CORE_ERROR		=>	'Core Error',
+				E_CORE_WARNING		=>	'Core Warning',
+				E_COMPILE_ERROR		=>	'Compile Error',
+				E_COMPILE_WARNING	=>	'Compile Warning',
+				E_USER_ERROR		=>	'User Error',
+				E_USER_WARNING		=>	'User Warning',
+				E_USER_NOTICE		=>	'User Notice',
+				E_STRICT		=>	'Runtime Notice'
+			);
 
-
-	/**
-	 * Constructor
-	 */
 	public function __construct()
 	{
 		$this->ob_level = ob_get_level();
-		// Note:  Do not log messages from this constructor.
+		// Note: Do not log messages from this constructor.
 	}
 
 	// --------------------------------------------------------------------
@@ -89,17 +84,15 @@
 	 *
 	 * This function logs PHP generated error messages
 	 *
-	 * @access	private
 	 * @param	string	the error severity
 	 * @param	string	the error string
 	 * @param	string	the error filepath
 	 * @param	string	the error line number
-	 * @return	string
+	 * @return	void
 	 */
-	function log_exception($severity, $message, $filepath, $line)
+	public function log_exception($severity, $message, $filepath, $line)
 	{
 		$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
 		log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);
 	}
 
@@ -108,15 +101,14 @@
 	/**
 	 * 404 Page Not Found Handler
 	 *
-	 * @access	private
 	 * @param	string	the page
 	 * @param 	bool	log error yes/no
 	 * @return	string
 	 */
-	function show_404($page = '', $log_error = TRUE)
+	public function show_404($page = '', $log_error = TRUE)
 	{
-		$heading = "404 Page Not Found";
-		$message = "The page you requested was not found.";
+		$heading = '404 Page Not Found';
+		$message = 'The page you requested was not found.';
 
 		// By default we log this, but allow a dev to skip it
 		if ($log_error)
@@ -137,14 +129,13 @@
 	 * (either as a string or an array) and displays
 	 * it using the specified template.
 	 *
-	 * @access	private
 	 * @param	string	the heading
 	 * @param	string	the message
 	 * @param	string	the template name
 	 * @param 	int		the status code
 	 * @return	string
 	 */
-	function show_error($heading, $message, $template = 'error_general', $status_code = 500)
+	public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
 	{
 		set_status_header($status_code);
 
@@ -166,7 +157,6 @@
 	/**
 	 * Native PHP error handler
 	 *
-	 * @access	private
 	 * @param	string	the error severity
 	 * @param	string	the error string
 	 * @param	string	the error filepath
@@ -176,8 +166,7 @@
 	function show_php_error($severity, $message, $filepath, $line)
 	{
 		$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
-
-		$filepath = str_replace("\\", "/", $filepath);
+		$filepath = str_replace('\\', '/', $filepath);
 
 		// For safety reasons we do not show the full file path
 		if (FALSE !== strpos($filepath, '/'))
@@ -191,15 +180,13 @@
 			ob_end_flush();
 		}
 		ob_start();
-		include(APPPATH.'errors/error_php.php');
+		include(APPPATH.'errors/'.'error_php.php');
 		$buffer = ob_get_contents();
 		ob_end_clean();
 		echo $buffer;
 	}
 
-
 }
-// END Exceptions Class
 
 /* End of file Exceptions.php */
-/* Location: ./system/core/Exceptions.php */
\ No newline at end of file
+/* Location: ./system/core/Exceptions.php */
diff --git a/system/core/Hooks.php b/system/core/Hooks.php
index 174adcb..e1ac58e 100755
--- a/system/core/Hooks.php
+++ b/system/core/Hooks.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -45,28 +45,24 @@
 	 *
 	 * @var bool
 	 */
-	var $enabled		= FALSE;
+	public $enabled		= FALSE;
 	/**
 	 * List of all hooks set in config/hooks.php
 	 *
 	 * @var array
 	 */
-	var $hooks			= array();
+	public $hooks			= array();
 	/**
 	 * Determines wether hook is in progress, used to prevent infinte loops
 	 *
 	 * @var bool
 	 */
-	var $in_progress	= FALSE;
+	public $in_progress	= FALSE;
 
-	/**
-	 * Constructor
-	 *
-	 */
-	function __construct()
+	public function __construct()
 	{
 		$this->_initialize();
-		log_message('debug', "Hooks Class Initialized");
+		log_message('debug', 'Hooks Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -74,24 +70,20 @@
 	/**
 	 * Initialize the Hooks Preferences
 	 *
-	 * @access	private
 	 * @return	void
 	 */
-	function _initialize()
+	private function _initialize()
 	{
 		$CFG =& load_class('Config', 'core');
 
 		// If hooks are not enabled in the config file
 		// there is nothing else to do
-
 		if ($CFG->item('enable_hooks') == FALSE)
 		{
 			return;
 		}
 
 		// Grab the "hooks" definition file.
-		// If there are no hooks, we're done.
-
 		if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
 		{
 			include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
@@ -101,7 +93,7 @@
 			include(APPPATH.'config/hooks.php');
 		}
 
-
+		// If there are no hooks, we're done.
 		if ( ! isset($hook) OR ! is_array($hook))
 		{
 			return;
@@ -116,13 +108,12 @@
 	/**
 	 * Call Hook
 	 *
-	 * Calls a particular hook
+	 * Calls a particular hook. Called by CodeIgniter.php.
 	 *
-	 * @access	private
 	 * @param	string	the hook name
 	 * @return	mixed
 	 */
-	function _call_hook($which = '')
+	public function _call_hook($which = '')
 	{
 		if ( ! $this->enabled OR ! isset($this->hooks[$which]))
 		{
@@ -151,11 +142,10 @@
 	 *
 	 * Runs a particular hook
 	 *
-	 * @access	private
 	 * @param	array	the hook details
 	 * @return	bool
 	 */
-	function _run_hook($data)
+	protected function _run_hook($data)
 	{
 		if ( ! is_array($data))
 		{
@@ -168,7 +158,6 @@
 
 		// If the script being called happens to have the same
 		// hook call within it a loop can happen
-
 		if ($this->in_progress == TRUE)
 		{
 			return;
@@ -254,7 +243,5 @@
 
 }
 
-// END CI_Hooks class
-
 /* End of file Hooks.php */
-/* Location: ./system/core/Hooks.php */
\ No newline at end of file
+/* Location: ./system/core/Hooks.php */
diff --git a/system/core/Input.php b/system/core/Input.php
index 7cfa4c6..7a16e51 100755
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -45,39 +45,39 @@
 	 *
 	 * @var string
 	 */
-	var $ip_address				= FALSE;
+	public $ip_address				= FALSE;
 	/**
 	 * user agent (web browser) being used by the current user
 	 *
 	 * @var string
 	 */
-	var $user_agent				= FALSE;
+	public $user_agent				= FALSE;
 	/**
 	 * If FALSE, then $_GET will be set to an empty array
 	 *
 	 * @var bool
 	 */
-	var $_allow_get_array		= TRUE;
+	protected $_allow_get_array		= TRUE;
 	/**
 	 * If TRUE, then newlines are standardized
 	 *
 	 * @var bool
 	 */
-	var $_standardize_newlines	= TRUE;
+	protected $_standardize_newlines	= TRUE;
 	/**
 	 * Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
 	 * Set automatically based on config setting
 	 *
 	 * @var bool
 	 */
-	var $_enable_xss			= FALSE;
+	protected $_enable_xss			= FALSE;
 	/**
 	 * Enables a CSRF cookie token to be set.
 	 * Set automatically based on config setting
 	 *
 	 * @var bool
 	 */
-	var $_enable_csrf			= FALSE;
+	protected $_enable_csrf			= FALSE;
 	/**
 	 * List of all HTTP request headers
 	 *
@@ -85,21 +85,19 @@
 	 */
 	protected $headers			= array();
 
-
 	/**
 	 * Constructor
 	 *
 	 * Sets whether to globally enable the XSS processing
 	 * and whether to allow the $_GET array
-	 *
 	 */
 	public function __construct()
 	{
-		log_message('debug', "Input Class Initialized");
+		log_message('debug', 'Input Class Initialized');
 
 		$this->_allow_get_array	= (config_item('allow_get_array') === TRUE);
-		$this->_enable_xss		= (config_item('global_xss_filtering') === TRUE);
-		$this->_enable_csrf		= (config_item('csrf_protection') === TRUE);
+		$this->_enable_xss	= (config_item('global_xss_filtering') === TRUE);
+		$this->_enable_csrf	= (config_item('csrf_protection') === TRUE);
 
 		global $SEC;
 		$this->security =& $SEC;
@@ -122,7 +120,6 @@
 	 *
 	 * This is a helper function to retrieve values from global arrays
 	 *
-	 * @access	protected
 	 * @param	array
 	 * @param	string
 	 * @param	bool
@@ -148,7 +145,6 @@
 	/**
 	* Fetch an item from the GET array
 	*
-	* @access	public
 	* @param	string
 	* @param	bool
 	* @return	string
@@ -176,7 +172,6 @@
 	/**
 	* Fetch an item from the POST array
 	*
-	* @access	public
 	* @param	string
 	* @param	bool
 	* @return	string
@@ -205,21 +200,15 @@
 	/**
 	* Fetch an item from either the GET array or the POST
 	*
-	* @access	public
 	* @param	string	The index key
 	* @param	bool	XSS cleaning
 	* @return	string
 	*/
 	public function get_post($index = '', $xss_clean = FALSE)
 	{
-		if ( ! isset($_POST[$index]) )
-		{
-			return $this->get($index, $xss_clean);
-		}
-		else
-		{
-			return $this->post($index, $xss_clean);
-		}
+		return ( ! isset($_POST[$index]))
+			? $this->get($index, $xss_clean)
+			: $this->post($index, $xss_clean);
 	}
 
 	// --------------------------------------------------------------------
@@ -227,7 +216,6 @@
 	/**
 	* Fetch an item from the COOKIE array
 	*
-	* @access	public
 	* @param	string
 	* @param	bool
 	* @return	string
@@ -245,7 +233,6 @@
 	* Accepts six parameter, or you can submit an associative
 	* array in the first parameter containing all the values.
 	*
-	* @access	public
 	* @param	mixed
 	* @param	string	the value of the cookie
 	* @param	string	the number of seconds until expiration
@@ -303,7 +290,6 @@
 	/**
 	* Fetch an item from the SERVER array
 	*
-	* @access	public
 	* @param	string
 	* @param	bool
 	* @return	string
@@ -318,7 +304,6 @@
 	/**
 	* Fetch the IP Address
 	*
-	* @access	public
 	* @return	string
 	*/
 	public function ip_address()
@@ -335,7 +320,7 @@
 
 			$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
 		}
-		elseif (! $this->server('HTTP_CLIENT_IP') AND $this->server('REMOTE_ADDR'))
+		elseif ( ! $this->server('HTTP_CLIENT_IP') AND $this->server('REMOTE_ADDR'))
 		{
 			$this->ip_address = $_SERVER['REMOTE_ADDR'];
 		}
@@ -354,8 +339,7 @@
 
 		if ($this->ip_address === FALSE)
 		{
-			$this->ip_address = '0.0.0.0';
-			return $this->ip_address;
+			return $this->ip_address = '0.0.0.0';
 		}
 
 		if (strpos($this->ip_address, ',') !== FALSE)
@@ -366,7 +350,7 @@
 
 		if ( ! $this->valid_ip($this->ip_address))
 		{
-			$this->ip_address = '0.0.0.0';
+			return $this->ip_address = '0.0.0.0';
 		}
 
 		return $this->ip_address;
@@ -379,7 +363,6 @@
 	*
 	* Updated version suggested by Geert De Deckere
 	*
-	* @access	public
 	* @param	string
 	* @return	bool
 	*/
@@ -394,7 +377,7 @@
 		$ip_segments = explode('.', $ip);
 
 		// Always 4 segments needed
-		if (count($ip_segments) != 4)
+		if (count($ip_segments) !== 4)
 		{
 			return FALSE;
 		}
@@ -408,7 +391,7 @@
 		{
 			// IP segments must be digits and can not be
 			// longer than 3 digits or greater then 255
-			if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
+			if ($segment == '' OR preg_match('/[^0-9]/', $segment) OR $segment > 255 OR strlen($segment) > 3)
 			{
 				return FALSE;
 			}
@@ -422,7 +405,6 @@
 	/**
 	* User Agent
 	*
-	* @access	public
 	* @return	string
 	*/
 	public function user_agent()
@@ -432,9 +414,7 @@
 			return $this->user_agent;
 		}
 
-		$this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
-
-		return $this->user_agent;
+		return $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
 	}
 
 	// --------------------------------------------------------------------
@@ -444,22 +424,20 @@
 	*
 	* This function does the following:
 	*
-	* Unsets $_GET data (if query strings are not enabled)
+	* - Unsets $_GET data (if query strings are not enabled)
+	* - Unsets all globals if register_globals is enabled
+	* - Standardizes newline characters to \n
 	*
-	* Unsets all globals if register_globals is enabled
-	*
-	* Standardizes newline characters to \n
-	*
-	* @access	private
 	* @return	void
 	*/
-	private function _sanitize_globals()
+	protected function _sanitize_globals()
 	{
 		// It would be "wrong" to unset any of these GLOBALS.
 		$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
-							'_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
-							'system_folder', 'application_folder', 'BM', 'EXT',
-							'CFG', 'URI', 'RTR', 'OUT', 'IN');
+					'_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
+					'system_folder', 'application_folder', 'BM', 'EXT',
+					'CFG', 'URI', 'RTR', 'OUT', 'IN'
+				);
 
 		// Unset globals for securiy.
 		// This is effectively the same as register_globals = off
@@ -532,14 +510,13 @@
 		// Sanitize PHP_SELF
 		$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
 
-
 		// CSRF Protection check
 		if ($this->_enable_csrf == TRUE)
 		{
 			$this->security->csrf_verify();
 		}
 
-		log_message('debug', "Global POST and COOKIE data sanitized");
+		log_message('debug', 'Global POST and COOKIE data sanitized');
 	}
 
 	// --------------------------------------------------------------------
@@ -550,11 +527,10 @@
 	* This is a helper function. It escapes data and
 	* standardizes newline characters to \n
 	*
-	* @access	private
 	* @param	string
 	* @return	string
 	*/
-	private function _clean_input_data($str)
+	protected function _clean_input_data($str)
 	{
 		if (is_array($str))
 		{
@@ -592,12 +568,9 @@
 		}
 
 		// Standardize newlines if needed
-		if ($this->_standardize_newlines == TRUE)
+		if ($this->_standardize_newlines == TRUE AND strpos($str, "\r") !== FALSE)
 		{
-			if (strpos($str, "\r") !== FALSE)
-			{
-				$str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
-			}
+			return str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
 		}
 
 		return $str;
@@ -612,13 +585,12 @@
 	* from trying to exploit keys we make sure that keys are
 	* only named with alpha-numeric text and a few other items.
 	*
-	* @access	private
 	* @param	string
 	* @return	string
 	*/
-	private function _clean_input_keys($str)
+	protected function _clean_input_keys($str)
 	{
-		if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
+		if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
 		{
 			exit('Disallowed Key Characters.');
 		}
@@ -626,7 +598,7 @@
 		// Clean UTF-8 if supported
 		if (UTF8_ENABLED === TRUE)
 		{
-			$str = $this->uni->clean_string($str);
+			return $this->uni->clean_string($str);
 		}
 
 		return $str;
@@ -640,10 +612,8 @@
 	 * In Apache, you can simply call apache_request_headers(), however for
 	 * people running other webservers the function is undefined.
 	 *
-	 * @access	public
 	 * @param	bool XSS cleaning
-	 *
-	 * @return array
+	 * @return	array
 	 */
 	public function request_headers($xss_clean = FALSE)
 	{
@@ -658,7 +628,7 @@
 
 			foreach ($_SERVER as $key => $val)
 			{
-				if (strncmp($key, 'HTTP_', 5) === 0)
+				if (strpos($key, 'HTTP_') === 0)
 				{
 					$headers[substr($key, 5)] = $this->_fetch_from_array($_SERVER, $key, $xss_clean);
 				}
@@ -684,7 +654,6 @@
 	 *
 	 * Returns the value of a single member of the headers class member
 	 *
-	 * @access	public
 	 * @param 	string		array key for $this->headers
 	 * @param	boolean		XSS Clean or not
 	 * @return 	mixed		FALSE on failure, string on success
@@ -716,7 +685,6 @@
 	 *
 	 * Test to see if a request contains the HTTP_X_REQUESTED_WITH header
 	 *
-	 * @access	public
 	 * @return 	boolean
 	 */
 	public function is_ajax_request()
@@ -731,12 +699,11 @@
 	 *
 	 * Test to see if a request was made from the command line
 	 *
-	 * @access	public
 	 * @return 	boolean
 	 */
 	public function is_cli_request()
 	{
-		return (php_sapi_name() == 'cli') or defined('STDIN');
+		return (php_sapi_name() === 'cli') or defined('STDIN');
 	}
 
 }
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 5eb2801..088cb6c 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -43,22 +43,17 @@
 	 *
 	 * @var array
 	 */
-	var $language	= array();
+	public $language	= array();
 	/**
 	 * List of loaded language files
 	 *
 	 * @var array
 	 */
-	var $is_loaded	= array();
+	public $is_loaded	= array();
 
-	/**
-	 * Constructor
-	 *
-	 * @access	public
-	 */
-	function __construct()
+	public function __construct()
 	{
-		log_message('debug', "Language Class Initialized");
+		log_message('debug', 'Language Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -66,7 +61,6 @@
 	/**
 	 * Load a language file
 	 *
-	 * @access	public
 	 * @param	mixed	the name of the language file to be loaded. Can be an array
 	 * @param	string	the language (english, etc.)
 	 * @param	bool	return loaded array of translations
@@ -74,7 +68,7 @@
 	 * @param 	string	alternative path to look for language file
 	 * @return	mixed
 	 */
-	function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
+	public function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
 	{
 		$langfile = str_replace('.php', '', $langfile);
 
@@ -148,11 +142,10 @@
 	/**
 	 * Fetch a single line of text from the language array
 	 *
-	 * @access	public
 	 * @param	string	$line	the language line
 	 * @return	string
 	 */
-	function line($line = '')
+	public function line($line = '')
 	{
 		$value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
 
@@ -166,7 +159,6 @@
 	}
 
 }
-// END Language Class
 
 /* End of file Lang.php */
 /* Location: ./system/core/Lang.php */
diff --git a/system/core/Loader.php b/system/core/Loader.php
index c4a6b50..272fe42 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -45,88 +45,77 @@
 	 * Nesting level of the output buffering mechanism
 	 *
 	 * @var int
-	 * @access protected
 	 */
 	protected $_ci_ob_level;
 	/**
 	 * List of paths to load views from
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_view_paths		= array();
 	/**
 	 * List of paths to load libraries from
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_library_paths	= array();
 	/**
 	 * List of paths to load models from
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_model_paths		= array();
 	/**
 	 * List of paths to load helpers from
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_helper_paths		= array();
 	/**
 	 * List of loaded base classes
-	 * Set by the controller class
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_base_classes		= array(); // Set by the controller class
 	/**
 	 * List of cached variables
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_cached_vars		= array();
 	/**
 	 * List of loaded classes
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_classes			= array();
 	/**
 	 * List of loaded files
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_loaded_files		= array();
 	/**
 	 * List of loaded models
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_models			= array();
 	/**
 	 * List of loaded helpers
 	 *
 	 * @var array
-	 * @access protected
 	 */
 	protected $_ci_helpers			= array();
 	/**
 	 * List of class name mappings
 	 *
 	 * @var array
-	 * @access protected
 	 */
-	protected $_ci_varmap			= array('unit_test' => 'unit',
-											'user_agent' => 'agent');
+	protected $_ci_varmap			= array(
+							'unit_test' => 'unit',
+							'user_agent' => 'agent'
+							);
 
 	/**
 	 * Constructor
@@ -141,7 +130,7 @@
 		$this->_ci_model_paths = array(APPPATH);
 		$this->_ci_view_paths = array(VIEWPATH	=> TRUE);
 
-		log_message('debug', "Loader Class Initialized");
+		log_message('debug', 'Loader Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -162,7 +151,6 @@
 		$this->_base_classes =& is_loaded();
 
 		$this->_ci_autoloader();
-
 		return $this;
 	}
 
@@ -311,9 +299,7 @@
 			require_once($mod_path.'models/'.$path.$model.'.php');
 
 			$model = ucfirst($model);
-
 			$CI->$name = new $model();
-
 			$this->_ci_models[] = $name;
 			return;
 		}
@@ -350,7 +336,7 @@
 			return DB($params, $active_record);
 		}
 
-		// Initialize the db variable.  Needed to prevent
+		// Initialize the db variable. Needed to prevent
 		// reference errors with some configurations
 		$CI->db = '';
 
@@ -716,11 +702,11 @@
 
 		if ($path == '')
 		{
-			$void = array_shift($this->_ci_library_paths);
-			$void = array_shift($this->_ci_model_paths);
-			$void = array_shift($this->_ci_helper_paths);
-			$void = array_shift($this->_ci_view_paths);
-			$void = array_shift($config->_config_paths);
+			array_shift($this->_ci_library_paths);
+			array_shift($this->_ci_model_paths);
+			array_shift($this->_ci_helper_paths);
+			array_shift($this->_ci_view_paths);
+			array_shift($config->_config_paths);
 		}
 		else
 		{
@@ -808,7 +794,6 @@
 
 		// This allows anything loaded using $this->load (views, files, etc.)
 		// to become accessible from within the Controller and Model functions.
-
 		$_ci_CI =& get_instance();
 		foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
 		{
@@ -837,12 +822,11 @@
 		 *
 		 * We buffer the output for two reasons:
 		 * 1. Speed. You get a significant speed boost.
-		 * 2. So that the final rendered template can be
-		 * post-processed by the output class.  Why do we
-		 * need post processing?  For one thing, in order to
-		 * show the elapsed page load time.  Unless we
-		 * can intercept the content right before it's sent to
-		 * the browser and then stop the timer it won't be accurate.
+		 * 2. So that the final rendered template can be post-processed by
+		 *    the output class. Why do we need post processing? For one thing,
+		 *    in order to show the elapsed page load time. Unless we can
+		 *    intercept the content right before it's sent to the browser and
+		 *    then stop the timer it won't be accurate.
 		 */
 		ob_start();
 
@@ -915,10 +899,10 @@
 		if (($last_slash = strrpos($class, '/')) !== FALSE)
 		{
 			// Extract the path
-			$subdir = substr($class, 0, $last_slash + 1);
+			$subdir = substr($class, 0, ++$last_slash);
 
 			// Get the filename from the path
-			$class = substr($class, $last_slash + 1);
+			$class = substr($class, $last_slash);
 		}
 
 		// We'll test for both lowercase and capitalized versions of the file name
@@ -933,15 +917,15 @@
 
 				if ( ! file_exists($baseclass))
 				{
-					log_message('error', "Unable to load the requested class: ".$class);
-					show_error("Unable to load the requested class: ".$class);
+					log_message('error', 'Unable to load the requested class: '.$class);
+					show_error('Unable to load the requested class: '.$class);
 				}
 
-				// Safety:  Was the class already loaded by a previous call?
+				// Safety: Was the class already loaded by a previous call?
 				if (in_array($subclass, $this->_ci_loaded_files))
 				{
 					// Before we deem this to be a duplicate request, let's see
-					// if a custom object name is being supplied.  If so, we'll
+					// if a custom object name is being supplied. If so, we'll
 					// return a new instance of the object
 					if ( ! is_null($object_name))
 					{
@@ -953,7 +937,7 @@
 					}
 
 					$is_duplicate = TRUE;
-					log_message('debug', $class." class already loaded. Second attempt ignored.");
+					log_message('debug', $class.' class already loaded. Second attempt ignored.');
 					return;
 				}
 
@@ -970,17 +954,17 @@
 			{
 				$filepath = $path.'libraries/'.$subdir.$class.'.php';
 
-				// Does the file exist?  No?  Bummer...
+				// Does the file exist? No? Bummer...
 				if ( ! file_exists($filepath))
 				{
 					continue;
 				}
 
-				// Safety:  Was the class already loaded by a previous call?
+				// Safety: Was the class already loaded by a previous call?
 				if (in_array($filepath, $this->_ci_loaded_files))
 				{
 					// Before we deem this to be a duplicate request, let's see
-					// if a custom object name is being supplied.  If so, we'll
+					// if a custom object name is being supplied. If so, we'll
 					// return a new instance of the object
 					if ( ! is_null($object_name))
 					{
@@ -992,7 +976,7 @@
 					}
 
 					$is_duplicate = TRUE;
-					log_message('debug', $class." class already loaded. Second attempt ignored.");
+					log_message('debug', $class.' class already loaded. Second attempt ignored.');
 					return;
 				}
 
@@ -1003,7 +987,7 @@
 
 		} // END FOREACH
 
-		// One last attempt.  Maybe the library is in a subdirectory, but it wasn't specified?
+		// One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
 		if ($subdir == '')
 		{
 			$path = strtolower($class).'/'.$class;
@@ -1014,8 +998,8 @@
 		// We do not issue errors if the load call failed due to a duplicate request
 		if ($is_duplicate == FALSE)
 		{
-			log_message('error', "Unable to load the requested class: ".$class);
-			show_error("Unable to load the requested class: ".$class);
+			log_message('error', 'Unable to load the requested class: '.$class);
+			show_error('Unable to load the requested class: '.$class);
 		}
 	}
 
@@ -1094,12 +1078,12 @@
 		// Is the class name valid?
 		if ( ! class_exists($name))
 		{
-			log_message('error', "Non-existent class: ".$name);
-			show_error("Non-existent class: ".$class);
+			log_message('error', 'Non-existent class: '.$name);
+			show_error('Non-existent class: '.$class);
 		}
 
 		// Set the variable name we will assign the class to
-		// Was a custom class name supplied?  If so we'll use it
+		// Was a custom class name supplied? If so we'll use it
 		$class = strtolower($class);
 
 		if (is_null($object_name))
@@ -1181,13 +1165,6 @@
 			}
 		}
 
-		// A little tweak to remain backward compatible
-		// The $autoload['core'] item was deprecated
-		if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
-		{
-			$autoload['libraries'] = $autoload['core'];
-		}
-
 		// Load libraries
 		if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
 		{
@@ -1271,4 +1248,4 @@
 }
 
 /* End of file Loader.php */
-/* Location: ./system/core/Loader.php */
\ No newline at end of file
+/* Location: ./system/core/Loader.php */
diff --git a/system/core/Model.php b/system/core/Model.php
index fc64013..a595a6a 100755
--- a/system/core/Model.php
+++ b/system/core/Model.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -38,14 +38,9 @@
  */
 class CI_Model {
 
-	/**
-	 * Constructor
-	 *
-	 * @access public
-	 */
-	function __construct()
+	public function __construct()
 	{
-		log_message('debug', "Model Class Initialized");
+		log_message('debug', 'Model Class Initialized');
 	}
 
 	/**
@@ -55,15 +50,13 @@
 	 * syntax as controllers.
 	 *
 	 * @param	string
-	 * @access private
 	 */
-	function __get($key)
+	public function __get($key)
 	{
 		$CI =& get_instance();
 		return $CI->$key;
 	}
 }
-// END Model Class
 
 /* End of file Model.php */
-/* Location: ./system/core/Model.php */
\ No newline at end of file
+/* Location: ./system/core/Model.php */
diff --git a/system/core/Output.php b/system/core/Output.php
index e529f91..1beee73 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -44,64 +44,52 @@
 	 * Current output string
 	 *
 	 * @var string
-	 * @access 	protected
 	 */
 	protected $final_output;
 	/**
 	 * Cache expiration time
 	 *
 	 * @var int
-	 * @access 	protected
 	 */
 	protected $cache_expiration	= 0;
 	/**
 	 * List of server headers
 	 *
 	 * @var array
-	 * @access 	protected
 	 */
 	protected $headers			= array();
 	/**
 	 * List of mime types
 	 *
 	 * @var array
-	 * @access 	protected
 	 */
 	protected $mime_types		= array();
 	/**
 	 * Determines wether profiler is enabled
 	 *
 	 * @var book
-	 * @access 	protected
 	 */
 	protected $enable_profiler	= FALSE;
 	/**
 	 * Determines if output compression is enabled
 	 *
 	 * @var bool
-	 * @access 	protected
 	 */
 	protected $_zlib_oc			= FALSE;
 	/**
 	 * List of profiler sections
 	 *
 	 * @var array
-	 * @access 	protected
 	 */
 	protected $_profiler_sections = array();
 	/**
 	 * Whether or not to parse variables like {elapsed_time} and {memory_usage}
 	 *
 	 * @var bool
-	 * @access 	protected
 	 */
 	protected $parse_exec_vars	= TRUE;
 
-	/**
-	 * Constructor
-	 *
-	 */
-	function __construct()
+	public function __construct()
 	{
 		$this->_zlib_oc = @ini_get('zlib.output_compression');
 
@@ -117,8 +105,7 @@
 
 
 		$this->mime_types = $mimes;
-
-		log_message('debug', "Output Class Initialized");
+		log_message('debug', 'Output Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -128,10 +115,9 @@
 	 *
 	 * Returns the current output string
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function get_output()
+	public function get_output()
 	{
 		return $this->final_output;
 	}
@@ -147,10 +133,9 @@
 	 * @param	string
 	 * @return	void
 	 */
-	function set_output($output)
+	public function set_output($output)
 	{
 		$this->final_output = $output;
-
 		return $this;
 	}
 
@@ -161,11 +146,10 @@
 	 *
 	 * Appends data onto the output string
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	void
 	 */
-	function append_output($output)
+	public function append_output($output)
 	{
 		if ($this->final_output == '')
 		{
@@ -189,25 +173,22 @@
 	 * Note:  If a file is cached, headers will not be sent.  We need to figure out
 	 * how to permit header data to be saved with the cache data...
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param 	bool
 	 * @return	void
 	 */
-	function set_header($header, $replace = TRUE)
+	public function set_header($header, $replace = TRUE)
 	{
 		// If zlib.output_compression is enabled it will compress the output,
 		// but it will not modify the content-length header to compensate for
 		// the reduction, causing the browser to hang waiting for more data.
 		// We'll just skip content-length in those cases.
-
 		if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0)
 		{
 			return;
 		}
 
 		$this->headers[] = array($header, $replace);
-
 		return $this;
 	}
 
@@ -216,11 +197,10 @@
 	/**
 	 * Set Content Type Header
 	 *
-	 * @access	public
 	 * @param	string	extension of the file we're outputting
 	 * @return	void
 	 */
-	function set_content_type($mime_type)
+	public function set_content_type($mime_type)
 	{
 		if (strpos($mime_type, '/') === FALSE)
 		{
@@ -241,7 +221,6 @@
 		$header = 'Content-Type: '.$mime_type;
 
 		$this->headers[] = array($header, TRUE);
-
 		return $this;
 	}
 
@@ -251,15 +230,13 @@
 	 * Set HTTP Status Header
 	 * moved to Common procedural functions in 1.7.2
 	 *
-	 * @access	public
 	 * @param	int		the status code
 	 * @param	string
 	 * @return	void
 	 */
-	function set_status_header($code = 200, $text = '')
+	public function set_status_header($code = 200, $text = '')
 	{
 		set_status_header($code, $text);
-
 		return $this;
 	}
 
@@ -268,14 +245,12 @@
 	/**
 	 * Enable/disable Profiler
 	 *
-	 * @access	public
 	 * @param	bool
 	 * @return	void
 	 */
-	function enable_profiler($val = TRUE)
+	public function enable_profiler($val = TRUE)
 	{
 		$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
-
 		return $this;
 	}
 
@@ -286,11 +261,10 @@
 	 *
 	 * Allows override of default / config settings for Profiler section display
 	 *
-	 * @access	public
 	 * @param	array
 	 * @return	void
 	 */
-	function set_profiler_sections($sections)
+	public function set_profiler_sections($sections)
 	{
 		foreach ($sections as $section => $enable)
 		{
@@ -305,14 +279,12 @@
 	/**
 	 * Set Cache
 	 *
-	 * @access	public
 	 * @param	integer
 	 * @return	void
 	 */
-	function cache($time)
+	publi function cache($time)
 	{
 		$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
-
 		return $this;
 	}
 
@@ -329,11 +301,10 @@
 	 * with any server headers and profile data.  It also stops the
 	 * benchmark timer so the page rendering speed and memory usage can be shown.
 	 *
-	 * @access	public
 	 * @param 	string
 	 * @return	mixed
 	 */
-	function _display($output = '')
+	public function _display($output = '')
 	{
 		// Note:  We use globals because we can't use $CI =& get_instance()
 		// since this function is sometimes called by the caching mechanism,
@@ -375,22 +346,17 @@
 		{
 			$memory	 = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
 
-			$output = str_replace('{elapsed_time}', $elapsed, $output);
-			$output = str_replace('{memory_usage}', $memory, $output);
+			$output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
 		}
 
 		// --------------------------------------------------------------------
 
 		// Is compression requested?
-		if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE)
+		if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE
+			&& extension_loaded('zlib')
+			&& isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
 		{
-			if (extension_loaded('zlib'))
-			{
-				if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
-				{
-					ob_start('ob_gzhandler');
-				}
-			}
+			ob_start('ob_gzhandler');
 		}
 
 		// --------------------------------------------------------------------
@@ -412,8 +378,8 @@
 		if ( ! isset($CI))
 		{
 			echo $output;
-			log_message('debug', "Final output sent to browser");
-			log_message('debug', "Total execution time: ".$elapsed);
+			log_message('debug', 'Final output sent to browser');
+			log_message('debug', 'Total execution time: '.$elapsed);
 			return TRUE;
 		}
 
@@ -424,7 +390,6 @@
 		if ($this->enable_profiler == TRUE)
 		{
 			$CI->load->library('profiler');
-
 			if ( ! empty($this->_profiler_sections))
 			{
 				$CI->profiler->set_sections($this->_profiler_sections);
@@ -432,16 +397,11 @@
 
 			// If the output data contains closing </body> and </html> tags
 			// we will remove them and add them back after we insert the profile data
-			if (preg_match("|</body>.*?</html>|is", $output))
+			$output = preg_replace('|</body>.*?</html>|is', '', $output, $count).$CI->profiler->run();
+			if ($count > 0)
 			{
-				$output  = preg_replace("|</body>.*?</html>|is", '', $output);
-				$output .= $CI->profiler->run();
 				$output .= '</body></html>';
 			}
-			else
-			{
-				$output .= $CI->profiler->run();
-			}
 		}
 
 		// --------------------------------------------------------------------
@@ -457,8 +417,8 @@
 			echo $output;  // Send it to the browser!
 		}
 
-		log_message('debug', "Final output sent to browser");
-		log_message('debug', "Total execution time: ".$elapsed);
+		log_message('debug', 'Final output sent to browser');
+		log_message('debug', 'Total execution time: '.$elapsed);
 	}
 
 	// --------------------------------------------------------------------
@@ -466,20 +426,18 @@
 	/**
 	 * Write a Cache File
 	 *
-	 * @access	public
 	 * @param 	string
 	 * @return	void
 	 */
-	function _write_cache($output)
+	public function _write_cache($output)
 	{
 		$CI =& get_instance();
 		$path = $CI->config->item('cache_path');
-
 		$cache_path = ($path == '') ? APPPATH.'cache/' : $path;
 
 		if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
 		{
-			log_message('error', "Unable to write cache file: ".$cache_path);
+			log_message('error', 'Unable to write cache file: '.$cache_path);
 			return;
 		}
 
@@ -491,7 +449,7 @@
 
 		if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
 		{
-			log_message('error', "Unable to write cache file: ".$cache_path);
+			log_message('error', 'Unable to write cache file: '.$cache_path);
 			return;
 		}
 
@@ -504,13 +462,13 @@
 		}
 		else
 		{
-			log_message('error', "Unable to secure a file lock for file at: ".$cache_path);
+			log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
 			return;
 		}
 		fclose($fp);
 		@chmod($cache_path, FILE_WRITE_MODE);
 
-		log_message('debug', "Cache file written: ".$cache_path);
+		log_message('debug', 'Cache file written: '.$cache_path);
 	}
 
 	// --------------------------------------------------------------------
@@ -518,69 +476,51 @@
 	/**
 	 * Update/serve a cached file
 	 *
-	 * @access	public
 	 * @param 	object	config class
 	 * @param 	object	uri class
 	 * @return	void
 	 */
-	function _display_cache(&$CFG, &$URI)
+	public function _display_cache(&$CFG, &$URI)
 	{
 		$cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
 
-		// Build the file path.  The file name is an MD5 hash of the full URI
-		$uri =	$CFG->item('base_url').
-				$CFG->item('index_page').
-				$URI->uri_string;
-
+		// Build the file path. The file name is an MD5 hash of the full URI
+		$uri =	$CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
 		$filepath = $cache_path.md5($uri);
 
-		if ( ! @file_exists($filepath))
-		{
-			return FALSE;
-		}
-
-		if ( ! $fp = @fopen($filepath, FOPEN_READ))
+		if ( ! @file_exists($filepath) OR ! $fp = @fopen($filepath, FOPEN_READ))
 		{
 			return FALSE;
 		}
 
 		flock($fp, LOCK_SH);
 
-		$cache = '';
-		if (filesize($filepath) > 0)
-		{
-			$cache = fread($fp, filesize($filepath));
-		}
+		$cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : '';
 
 		flock($fp, LOCK_UN);
 		fclose($fp);
 
 		// Strip out the embedded timestamp
-		if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
+		if ( ! preg_match('/(\d+TS--->)/', $cache, $match))
 		{
 			return FALSE;
 		}
 
 		// Has the file expired? If so we'll delete it.
-		if (time() >= trim(str_replace('TS--->', '', $match['1'])))
+		if (time() >= trim(str_replace('TS--->', '', $match[1])) && is_really_writable($cache_path))
 		{
-			if (is_really_writable($cache_path))
-			{
-				@unlink($filepath);
-				log_message('debug', "Cache file has expired. File deleted");
-				return FALSE;
-			}
+			@unlink($filepath);
+			log_message('debug', 'Cache file has expired. File deleted.');
+			return FALSE;
 		}
 
 		// Display the cache
-		$this->_display(str_replace($match['0'], '', $cache));
-		log_message('debug', "Cache file is current. Sending it to browser.");
+		$this->_display(str_replace($match[0], '', $cache));
+		log_message('debug', 'Cache file is current. Sending it to browser.');
 		return TRUE;
 	}
 
-
 }
-// END Output Class
 
 /* End of file Output.php */
-/* Location: ./system/core/Output.php */
\ No newline at end of file
+/* Location: ./system/core/Output.php */
diff --git a/system/core/Router.php b/system/core/Router.php
index 8cad868..d213195 100755
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -44,62 +44,55 @@
 	 * Config class
 	 *
 	 * @var object
-	 * @access public
 	 */
-	var $config;
+	public $config;
 	/**
 	 * List of routes
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var $routes			= array();
+	public $routes			= array();
 	/**
 	 * List of error routes
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var $error_routes	= array();
+	public $error_routes	= array();
 	/**
 	 * Current class name
 	 *
 	 * @var string
-	 * @access public
 	 */
-	var $class			= '';
+	public $class			= '';
 	/**
 	 * Current method name
 	 *
 	 * @var string
-	 * @access public
 	 */
-	var $method			= 'index';
+	public $method			= 'index';
 	/**
 	 * Sub-directory that contains the requested controller class
 	 *
 	 * @var string
-	 * @access public
 	 */
-	var $directory		= '';
+	public $directory		= '';
 	/**
 	 * Default controller (and method if specific)
 	 *
 	 * @var string
-	 * @access public
 	 */
-	var $default_controller;
+	public $default_controller;
 
 	/**
 	 * Constructor
 	 *
 	 * Runs the route mapping function.
 	 */
-	function __construct()
+	public function __construct()
 	{
 		$this->config =& load_class('Config', 'core');
 		$this->uri =& load_class('URI', 'core');
-		log_message('debug', "Router Class Initialized");
+		log_message('debug', 'Router Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -110,12 +103,11 @@
 	 * This function determines what should be served based on the URI request,
 	 * as well as any "routes" that have been set in the routing config file.
 	 *
-	 * @access	private
 	 * @return	void
 	 */
-	function _set_routing()
+	public function _set_routing()
 	{
-		// Are query strings enabled in the config file?  Normally CI doesn't utilize query strings
+		// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
 		// since URI segments are more search-engine friendly, but they can optionally be used.
 		// If this feature is enabled, we will gather the directory/class/method a little differently
 		$segments = array();
@@ -157,7 +149,7 @@
 		// the URI doesn't correlated to a valid controller.
 		$this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
 
-		// Were there any query string segments?  If so, we'll validate them and bail out since we're done.
+		// Were there any query string segments? If so, we'll validate them and bail out since we're done.
 		if (count($segments) > 0)
 		{
 			return $this->_validate_request($segments);
@@ -172,17 +164,10 @@
 			return $this->_set_default_controller();
 		}
 
-		// Do we need to remove the URL suffix?
-		$this->uri->_remove_url_suffix();
-
-		// Compile the segments into an array
-		$this->uri->_explode_segments();
-
-		// Parse any custom routing that may exist
-		$this->_parse_routes();
-
-		// Re-index the segment array so that it starts with 1 rather than 0
-		$this->uri->_reindex_segments();
+		$this->uri->_remove_url_suffix(); // Remove the URL suffix
+		$this->uri->_explode_segments(); // Compile the segments into an array
+		$this->_parse_routes(); // Parse any custom routing that may exist
+		$this->uri->_reindex_segments(); // Re-index the segment array so that it starts with 1 rather than 0
 	}
 
 	// --------------------------------------------------------------------
@@ -190,20 +175,18 @@
 	/**
 	 * Set the default controller
 	 *
-	 * @access	private
 	 * @return	void
 	 */
-	function _set_default_controller()
+	protected function _set_default_controller()
 	{
 		if ($this->default_controller === FALSE)
 		{
-			show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
+			show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
 		}
 		// Is the method being specified?
 		if (strpos($this->default_controller, '/') !== FALSE)
 		{
 			$x = explode('/', $this->default_controller);
-
 			$this->set_class($x[0]);
 			$this->set_method($x[1]);
 			$this->_set_request($x);
@@ -218,7 +201,7 @@
 		// re-index the routed segments array so it starts with 1 rather than 0
 		$this->uri->_reindex_segments();
 
-		log_message('debug', "No URI present. Default controller set.");
+		log_message('debug', 'No URI present. Default controller set.');
 	}
 
 	// --------------------------------------------------------------------
@@ -229,16 +212,15 @@
 	 * This function takes an array of URI segments as
 	 * input, and sets the current class/method
 	 *
-	 * @access	private
 	 * @param	array
 	 * @param	bool
 	 * @return	void
 	 */
-	function _set_request($segments = array())
+	protected function _set_request($segments = array())
 	{
 		$segments = $this->_validate_request($segments);
 
-		if (count($segments) == 0)
+		if (count($segments) === 0)
 		{
 			return $this->_set_default_controller();
 		}
@@ -269,13 +251,12 @@
 	 * Validates the supplied segments.  Attempts to determine the path to
 	 * the controller.
 	 *
-	 * @access	private
 	 * @param	array
 	 * @return	array
 	 */
-	function _validate_request($segments)
+	protected function _validate_request($segments)
 	{
-		if (count($segments) == 0)
+		if (count($segments) === 0)
 		{
 			return $segments;
 		}
@@ -301,7 +282,6 @@
 					if ( ! empty($this->routes['404_override']))
 					{
 						$x = explode('/', $this->routes['404_override']);
-
 						$this->set_directory('');
 						$this->set_class($x[0]);
 						$this->set_method(isset($x[1]) ? $x[1] : 'index');
@@ -320,7 +300,6 @@
 				if (strpos($this->default_controller, '/') !== FALSE)
 				{
 					$x = explode('/', $this->default_controller);
-
 					$this->set_class($x[0]);
 					$this->set_method($x[1]);
 				}
@@ -344,18 +323,16 @@
 
 
 		// If we've gotten this far it means that the URI does not correlate to a valid
-		// controller class.  We will now see if there is an override
+		// controller class. We will now see if there is an override
 		if ( ! empty($this->routes['404_override']))
 		{
 			$x = explode('/', $this->routes['404_override']);
-
 			$this->set_class($x[0]);
 			$this->set_method(isset($x[1]) ? $x[1] : 'index');
 
 			return $x;
 		}
 
-
 		// Nothing else to do at this point but show a 404
 		show_404($segments[0]);
 	}
@@ -369,10 +346,9 @@
 	 * the config/routes.php file against the URI to
 	 * determine if the class/method need to be remapped.
 	 *
-	 * @access	private
 	 * @return	void
 	 */
-	function _parse_routes()
+	protected function _parse_routes()
 	{
 		// Turn the segment array into a URI string
 		$uri = implode('/', $this->uri->segments);
@@ -387,7 +363,7 @@
 		foreach ($this->routes as $key => $val)
 		{
 			// Convert wild-cards to RegEx
-			$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
+			$key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key);
 
 			// Does the RegEx match?
 			if (preg_match('#^'.$key.'$#', $uri))
@@ -412,11 +388,10 @@
 	/**
 	 * Set the class name
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	void
 	 */
-	function set_class($class)
+	public function set_class($class)
 	{
 		$this->class = str_replace(array('/', '.'), '', $class);
 	}
@@ -426,10 +401,9 @@
 	/**
 	 * Fetch the current class
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function fetch_class()
+	public function fetch_class()
 	{
 		return $this->class;
 	}
@@ -439,11 +413,10 @@
 	/**
 	 *  Set the method name
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	void
 	 */
-	function set_method($method)
+	public function set_method($method)
 	{
 		$this->method = $method;
 	}
@@ -453,10 +426,9 @@
 	/**
 	 *  Fetch the current method
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function fetch_method()
+	public function fetch_method()
 	{
 		if ($this->method == $this->fetch_class())
 		{
@@ -471,11 +443,10 @@
 	/**
 	 *  Set the directory name
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	void
 	 */
-	function set_directory($dir)
+	public function set_directory($dir)
 	{
 		$this->directory = str_replace(array('/', '.'), '', $dir).'/';
 	}
@@ -485,10 +456,9 @@
 	/**
 	 *  Fetch the sub-directory (if any) that contains the requested controller class
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function fetch_directory()
+	public function fetch_directory()
 	{
 		return $this->directory;
 	}
@@ -498,11 +468,10 @@
 	/**
 	 *  Set the controller overrides
 	 *
-	 * @access	public
 	 * @param	array
 	 * @return	null
 	 */
-	function _set_overrides($routing)
+	public function _set_overrides($routing)
 	{
 		if ( ! is_array($routing))
 		{
@@ -526,9 +495,7 @@
 		}
 	}
 
-
 }
-// END Router Class
 
 /* End of file Router.php */
-/* Location: ./system/core/Router.php */
\ No newline at end of file
+/* Location: ./system/core/Router.php */
diff --git a/system/core/Security.php b/system/core/Security.php
index d0d3c08..f09298b 100755
--- a/system/core/Security.php
+++ b/system/core/Security.php
@@ -169,9 +169,14 @@
 		// polute the _POST array
 		unset($_POST[$this->_csrf_token_name]);
 
-		// Nothing should last forever
-		unset($_COOKIE[$this->_csrf_cookie_name]);
-		$this->_csrf_hash = '';
+		// Regenerate on every submission?
+		if (config_item('csrf_regenerate'))
+		{
+			// Nothing should last forever
+			unset($_COOKIE[$this->_csrf_cookie_name]);
+			$this->_csrf_hash = '';
+		}
+		
 		$this->_csrf_set_hash();
 		$this->csrf_set_cookie();
 
diff --git a/system/core/URI.php b/system/core/URI.php
index 3c26d30..eaf7b75 100755
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -44,62 +44,56 @@
 	 * List of cached uri segments
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var	$keyval			= array();
+	public $keyval		= array();
 	/**
 	 * Current uri string
 	 *
 	 * @var string
-	 * @access public
 	 */
-	var $uri_string;
+	public $uri_string;
 	/**
 	 * List of uri segments
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var $segments		= array();
+	public $segments	= array();
 	/**
 	 * Re-indexed list of uri segments
 	 * Starts at 1 instead of 0
 	 *
 	 * @var array
-	 * @access public
 	 */
-	var $rsegments		= array();
+	public $rsegments	= array();
 
 	/**
 	 * Constructor
 	 *
-	 * Simply globalizes the $RTR object.  The front
+	 * Simply globalizes the $RTR object. The front
 	 * loads the Router class early on so it's not available
 	 * normally as other classes are.
-	 *
-	 * @access	public
 	 */
-	function __construct()
+	public function __construct()
 	{
 		$this->config =& load_class('Config', 'core');
-		log_message('debug', "URI Class Initialized");
+		log_message('debug', 'URI Class Initialized');
 	}
 
-
 	// --------------------------------------------------------------------
 
 	/**
 	 * Get the URI String
 	 *
-	 * @access	private
-	 * @return	string
+	 * Called by CI_Router
+	 *
+	 * @return	void
 	 */
-	function _fetch_uri_string()
+	public function _fetch_uri_string()
 	{
-		if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
+		if (strtoupper($this->config->item('uri_protocol')) === 'AUTO')
 		{
 			// Is the request coming from the command line?
-			if (php_sapi_name() == 'cli' or defined('STDIN'))
+			if (php_sapi_name() === 'cli' OR defined('STDIN'))
 			{
 				$this->_set_uri_string($this->_parse_cli_args());
 				return;
@@ -115,14 +109,14 @@
 			// Is there a PATH_INFO variable?
 			// Note: some servers seem to have trouble with getenv() so we'll test it two ways
 			$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
-			if (trim($path, '/') != '' && $path != "/".SELF)
+			if (trim($path, '/') != '' && $path !== '/'.SELF)
 			{
 				$this->_set_uri_string($path);
 				return;
 			}
 
 			// No PATH_INFO?... What about QUERY_STRING?
-			$path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+			$path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
 			if (trim($path, '/') != '')
 			{
 				$this->_set_uri_string($path);
@@ -130,7 +124,7 @@
 			}
 
 			// As a last ditch effort lets try using the $_GET array
-			if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
+			if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '')
 			{
 				$this->_set_uri_string(key($_GET));
 				return;
@@ -143,12 +137,12 @@
 
 		$uri = strtoupper($this->config->item('uri_protocol'));
 
-		if ($uri == 'REQUEST_URI')
+		if ($uri === 'REQUEST_URI')
 		{
 			$this->_set_uri_string($this->_detect_uri());
 			return;
 		}
-		elseif ($uri == 'CLI')
+		elseif ($uri === 'CLI')
 		{
 			$this->_set_uri_string($this->_parse_cli_args());
 			return;
@@ -163,17 +157,16 @@
 	/**
 	 * Set the URI String
 	 *
-	 * @access	public
 	 * @param 	string
-	 * @return	string
+	 * @return	void
 	 */
-	function _set_uri_string($str)
+	public function _set_uri_string($str)
 	{
 		// Filter out control characters
 		$str = remove_invisible_characters($str, FALSE);
 
 		// If the URI contains only a slash we'll kill it
-		$this->uri_string = ($str == '/') ? '' : $str;
+		$this->uri_string = ($str === '/') ? '' : $str;
 	}
 
 	// --------------------------------------------------------------------
@@ -184,7 +177,6 @@
 	 * This function will detect the URI automatically and fix the query string
 	 * if necessary.
 	 *
-	 * @access	private
 	 * @return	string
 	 */
 	protected function _detect_uri()
@@ -194,12 +186,11 @@
 			return '';
 		}
 
-		$uri = $_SERVER['REQUEST_URI'];
-		if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
+		if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0)
 		{
 			$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
 		}
-		elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
+		elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0)
 		{
 			$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
 		}
@@ -223,7 +214,7 @@
 			$_GET = array();
 		}
 
-		if ($uri == '/' || empty($uri))
+		if ($uri == '/' OR empty($uri))
 		{
 			return '/';
 		}
@@ -241,13 +232,11 @@
 	 *
 	 * Take each command line argument and assume it is a URI segment.
 	 *
-	 * @access	private
 	 * @return	string
 	 */
 	protected function _parse_cli_args()
 	{
 		$args = array_slice($_SERVER['argv'], 1);
-
 		return $args ? '/' . implode('/', $args) : '';
 	}
 
@@ -256,27 +245,28 @@
 	/**
 	 * Filter segments for malicious characters
 	 *
-	 * @access	private
+	 * Called by CI_Router
+	 *
 	 * @param	string
 	 * @return	string
 	 */
-	function _filter_uri($str)
+	public function _filter_uri($str)
 	{
 		if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
 		{
 			// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
 			// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
-			if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
+			if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str))
 			{
 				show_error('The URI you submitted has disallowed characters.', 400);
 			}
 		}
 
-		// Convert programatic characters to entities
-		$bad	= array('$',		'(',		')',		'%28',		'%29');
-		$good	= array('&#36;',	'&#40;',	'&#41;',	'&#40;',	'&#41;');
-
-		return str_replace($bad, $good, $str);
+		// Convert programatic characters to entities and return
+		return str_replace(
+					array('$',     '(',     ')',     '%28',   '%29'), // Bad
+					array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;'), // Good
+					$str);
 	}
 
 	// --------------------------------------------------------------------
@@ -284,14 +274,15 @@
 	/**
 	 * Remove the suffix from the URL if needed
 	 *
-	 * @access	private
+	 * Called by CI_Router
+	 *
 	 * @return	void
 	 */
-	function _remove_url_suffix()
+	public function _remove_url_suffix()
 	{
-		if  ($this->config->item('url_suffix') != "")
+		if  ($this->config->item('url_suffix') != '')
 		{
-			$this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
+			$this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string);
 		}
 	}
 
@@ -301,12 +292,13 @@
 	 * Explode the URI Segments. The individual segments will
 	 * be stored in the $this->segments array.
 	 *
-	 * @access	private
+	 * Called by CI_Router
+	 *
 	 * @return	void
 	 */
-	function _explode_segments()
+	public function _explode_segments()
 	{
-		foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
+		foreach (explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $this->uri_string)) as $val)
 		{
 			// Filter segments for security
 			$val = trim($this->_filter_uri($val));
@@ -323,14 +315,15 @@
 	 * Re-index Segments
 	 *
 	 * This function re-indexes the $this->segment array so that it
-	 * starts at 1 rather than 0.  Doing so makes it simpler to
+	 * starts at 1 rather than 0. Doing so makes it simpler to
 	 * use functions like $this->uri->segment(n) since there is
 	 * a 1:1 relationship between the segment array and the actual segments.
 	 *
-	 * @access	private
+	 * Called by CI_Router
+	 *
 	 * @return	void
 	 */
-	function _reindex_segments()
+	public function _reindex_segments()
 	{
 		array_unshift($this->segments, NULL);
 		array_unshift($this->rsegments, NULL);
@@ -345,12 +338,11 @@
 	 *
 	 * This function returns the URI segment based on the number provided.
 	 *
-	 * @access	public
 	 * @param	integer
 	 * @param	bool
 	 * @return	string
 	 */
-	function segment($n, $no_result = FALSE)
+	public function segment($n, $no_result = FALSE)
 	{
 		return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
 	}
@@ -364,12 +356,11 @@
 	 * based on the number provided.  If there is no routing this function returns the
 	 * same result as $this->segment()
 	 *
-	 * @access	public
 	 * @param	integer
 	 * @param	bool
 	 * @return	string
 	 */
-	function rsegment($n, $no_result = FALSE)
+	public function rsegment($n, $no_result = FALSE)
 	{
 		return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
 	}
@@ -392,25 +383,22 @@
 	 *			gender => male
 	 *		 )
 	 *
-	 * @access	public
 	 * @param	integer	the starting segment number
 	 * @param	array	an array of default values
 	 * @return	array
 	 */
-	function uri_to_assoc($n = 3, $default = array())
+	public function uri_to_assoc($n = 3, $default = array())
 	{
 		return $this->_uri_to_assoc($n, $default, 'segment');
 	}
 	/**
 	 * Identical to above only it uses the re-routed segment array
 	 *
-	 * @access 	public
 	 * @param 	integer	the starting segment number
 	 * @param 	array	an array of default values
 	 * @return 	array
-	 *
 	 */
-	function ruri_to_assoc($n = 3, $default = array())
+	public function ruri_to_assoc($n = 3, $default = array())
 	{
 		return $this->_uri_to_assoc($n, $default, 'rsegment');
 	}
@@ -420,25 +408,13 @@
 	/**
 	 * Generate a key value pair from the URI string or Re-routed URI string
 	 *
-	 * @access	private
 	 * @param	integer	the starting segment number
 	 * @param	array	an array of default values
 	 * @param	string	which array we should use
 	 * @return	array
 	 */
-	function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
+	protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
 	{
-		if ($which == 'segment')
-		{
-			$total_segments = 'total_segments';
-			$segment_array = 'segment_array';
-		}
-		else
-		{
-			$total_segments = 'total_rsegments';
-			$segment_array = 'rsegment_array';
-		}
-
 		if ( ! is_numeric($n))
 		{
 			return $default;
@@ -449,23 +425,30 @@
 			return $this->keyval[$n];
 		}
 
+		if ($which === 'segment')
+		{
+			$total_segments = 'total_segments';
+			$segment_array = 'segment_array';
+		}
+		else
+		{
+			$total_segments = 'total_rsegments';
+			$segment_array = 'rsegment_array';
+		}
+
 		if ($this->$total_segments() < $n)
 		{
-			if (count($default) == 0)
+			if (count($default) === 0)
 			{
 				return array();
 			}
 
-			$retval = array();
-			foreach ($default as $val)
-			{
-				$retval[$val] = FALSE;
-			}
-			return $retval;
+			return function_exists('array_fill_keys')
+				? array_fill_keys($default, FALSE)
+				: array_combine($default, array_fill(0, count($default), FALSE));
 		}
 
 		$segments = array_slice($this->$segment_array(), ($n - 1));
-
 		$i = 0;
 		$lastval = '';
 		$retval  = array();
@@ -506,11 +489,10 @@
 	 * Generate a URI string from an associative array
 	 *
 	 *
-	 * @access	public
 	 * @param	array	an associative array of key/values
 	 * @return	array
 	 */
-	function assoc_to_uri($array)
+	public function assoc_to_uri($array)
 	{
 		$temp = array();
 		foreach ((array)$array as $key => $val)
@@ -527,12 +509,11 @@
 	/**
 	 * Fetch a URI Segment and add a trailing slash
 	 *
-	 * @access	public
 	 * @param	integer
 	 * @param	string
 	 * @return	string
 	 */
-	function slash_segment($n, $where = 'trailing')
+	public function slash_segment($n, $where = 'trailing')
 	{
 		return $this->_slash_segment($n, $where, 'segment');
 	}
@@ -542,12 +523,11 @@
 	/**
 	 * Fetch a URI Segment and add a trailing slash
 	 *
-	 * @access	public
 	 * @param	integer
 	 * @param	string
 	 * @return	string
 	 */
-	function slash_rsegment($n, $where = 'trailing')
+	public function slash_rsegment($n, $where = 'trailing')
 	{
 		return $this->_slash_segment($n, $where, 'rsegment');
 	}
@@ -557,22 +537,20 @@
 	/**
 	 * Fetch a URI Segment and add a trailing slash - helper function
 	 *
-	 * @access	private
 	 * @param	integer
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function _slash_segment($n, $where = 'trailing', $which = 'segment')
+	protected function _slash_segment($n, $where = 'trailing', $which = 'segment')
 	{
-		$leading	= '/';
-		$trailing	= '/';
+		$leading = $trailing = '/';
 
-		if ($where == 'trailing')
+		if ($where === 'trailing')
 		{
 			$leading	= '';
 		}
-		elseif ($where == 'leading')
+		elseif ($where === 'leading')
 		{
 			$trailing	= '';
 		}
@@ -585,10 +563,9 @@
 	/**
 	 * Segment Array
 	 *
-	 * @access	public
 	 * @return	array
 	 */
-	function segment_array()
+	public function segment_array()
 	{
 		return $this->segments;
 	}
@@ -598,10 +575,9 @@
 	/**
 	 * Routed Segment Array
 	 *
-	 * @access	public
 	 * @return	array
 	 */
-	function rsegment_array()
+	public function rsegment_array()
 	{
 		return $this->rsegments;
 	}
@@ -611,10 +587,9 @@
 	/**
 	 * Total number of segments
 	 *
-	 * @access	public
 	 * @return	integer
 	 */
-	function total_segments()
+	public function total_segments()
 	{
 		return count($this->segments);
 	}
@@ -624,10 +599,9 @@
 	/**
 	 * Total number of routed segments
 	 *
-	 * @access	public
 	 * @return	integer
 	 */
-	function total_rsegments()
+	public function total_rsegments()
 	{
 		return count($this->rsegments);
 	}
@@ -637,10 +611,9 @@
 	/**
 	 * Fetch the entire URI string
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function uri_string()
+	public function uri_string()
 	{
 		return $this->uri_string;
 	}
@@ -651,16 +624,14 @@
 	/**
 	 * Fetch the entire Re-routed URI string
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function ruri_string()
+	public function ruri_string()
 	{
 		return '/'.implode('/', $this->rsegment_array());
 	}
 
 }
-// END URI Class
 
 /* End of file URI.php */
-/* Location: ./system/core/URI.php */
\ No newline at end of file
+/* Location: ./system/core/URI.php */
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index 40a7ac4..0e180d3 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -47,20 +47,19 @@
 	 */
 	public function __construct()
 	{
-		log_message('debug', "Utf8 Class Initialized");
+		log_message('debug', 'Utf8 Class Initialized');
 
 		global $CFG;
 
 		if (
 			@preg_match('/./u', 'é') === 1		// PCRE must support UTF-8
 			&& function_exists('iconv')			// iconv must be installed
-			&& ini_get('mbstring.func_overload') !== 1	// Multibyte string function overloading cannot be enabled
-			&& $CFG->item('charset') == 'UTF-8'			// Application charset must be UTF-8
+			&& @ini_get('mbstring.func_overload') != 1	// Multibyte string function overloading cannot be enabled
+			&& $CFG->item('charset') === 'UTF-8'		// Application charset must be UTF-8
 			)
 		{
-			log_message('debug', "UTF-8 Support Enabled");
-
 			define('UTF8_ENABLED', TRUE);
+			log_message('debug', 'UTF-8 Support Enabled');
 
 			// set internal encoding for multibyte string functions if necessary
 			// and set a flag so we don't have to repeatedly use extension_loaded()
@@ -77,8 +76,8 @@
 		}
 		else
 		{
-			log_message('debug', "UTF-8 Support Disabled");
 			define('UTF8_ENABLED', FALSE);
+			log_message('debug', 'UTF-8 Support Disabled');
 		}
 	}
 
@@ -134,18 +133,14 @@
 	{
 		if (function_exists('iconv'))
 		{
-			$str = @iconv($encoding, 'UTF-8', $str);
+			return @iconv($encoding, 'UTF-8', $str);
 		}
 		elseif (function_exists('mb_convert_encoding'))
 		{
-			$str = @mb_convert_encoding($str, 'UTF-8', $encoding);
-		}
-		else
-		{
-			return FALSE;
+			return @mb_convert_encoding($str, 'UTF-8', $encoding);
 		}
 
-		return $str;
+		return FALSE;
 	}
 
 	// --------------------------------------------------------------------
@@ -163,10 +158,7 @@
 		return (preg_match('/[^\x00-\x7F]/S', $str) === 0);
 	}
 
-	// --------------------------------------------------------------------
-
 }
-// End Utf8 Class
 
 /* End of file Utf8.php */
-/* Location: ./system/core/Utf8.php */
\ No newline at end of file
+/* Location: ./system/core/Utf8.php */
diff --git a/system/database/DB.php b/system/database/DB.php
index a0106c1..ed6afd7 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Initialize the database
  *
@@ -42,17 +40,15 @@
 	if (is_string($params) AND strpos($params, '://') === FALSE)
 	{
 		// Is the config file in the environment folder?
-		if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+		if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
+			AND ! file_exists($file_path = APPPATH.'config/database.php'))
 		{
-			if ( ! file_exists($file_path = APPPATH.'config/database.php'))
-			{
-				show_error('The configuration file database.php does not exist.');
-			}
+			show_error('The configuration file database.php does not exist.');
 		}
 
 		include($file_path);
 
-		if ( ! isset($db) OR count($db) == 0)
+		if ( ! isset($db) OR count($db) === 0)
 		{
 			show_error('No database connection settings were found in the database config file.');
 		}
@@ -78,33 +74,31 @@
 		 *  parameter. DSNs must have this prototype:
 		 *  $dsn = 'driver://username:password@hostname/database';
 		 */
-
 		if (($dns = @parse_url($params)) === FALSE)
 		{
 			show_error('Invalid DB Connection String');
 		}
 
 		$params = array(
-							'dbdriver'	=> $dns['scheme'],
-							'hostname'	=> (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
-							'username'	=> (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
-							'password'	=> (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
-							'database'	=> (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
-						);
+				'dbdriver'	=> $dns['scheme'],
+				'hostname'	=> (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
+				'username'	=> (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
+				'password'	=> (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
+				'database'	=> (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
+			);
 
 		// were additional config items set?
 		if (isset($dns['query']))
 		{
 			parse_str($dns['query'], $extra);
-
 			foreach ($extra as $key => $val)
 			{
 				// booleans please
-				if (strtoupper($val) == "TRUE")
+				if (strtoupper($val) === 'TRUE')
 				{
 					$val = TRUE;
 				}
-				elseif (strtoupper($val) == "FALSE")
+				elseif (strtoupper($val) === 'FALSE')
 				{
 					$val = FALSE;
 				}
@@ -114,17 +108,15 @@
 		}
 	}
 
-	// No DB specified yet?  Beat them senseless...
+	// No DB specified yet? Beat them senseless...
 	if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '')
 	{
 		show_error('You have not selected a database type to connect to.');
 	}
 
-	// Load the DB classes.  Note: Since the active record class is optional
+	// Load the DB classes. Note: Since the active record class is optional
 	// we need to dynamically create a class that extends proper parent class
 	// based on whether we're using the active record class or not.
-	// Kudos to Paul for discovering this clever use of eval()
-
 	if ($active_record_override !== NULL)
 	{
 		$active_record = $active_record_override;
@@ -135,18 +127,14 @@
 	if ( ! isset($active_record) OR $active_record == TRUE)
 	{
 		require_once(BASEPATH.'database/DB_active_rec.php');
-
 		if ( ! class_exists('CI_DB'))
 		{
 			class CI_DB extends CI_DB_active_record { }
 		}
 	}
-	else
+	elseif ( ! class_exists('CI_DB'))
 	{
-		if ( ! class_exists('CI_DB'))
-		{
-			class CI_DB extends CI_DB_driver { }
-		}
+		class CI_DB extends CI_DB_driver { }
 	}
 
 	require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
@@ -168,7 +156,5 @@
 	return $DB;
 }
 
-
-
 /* End of file DB.php */
-/* Location: ./system/database/DB.php */
\ No newline at end of file
+/* Location: ./system/database/DB.php */
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 486b4d7..71762a4 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -1,4 +1,4 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
@@ -43,23 +43,23 @@
 	protected $return_delete_sql		= FALSE;
 	protected $reset_delete_data		= FALSE;
 
-	protected $ar_select				= array();
-	protected $ar_distinct				= FALSE;
-	protected $ar_from					= array();
-	protected $ar_join					= array();
-	protected $ar_where					= array();
-	protected $ar_like					= array();
-	protected $ar_groupby				= array();
-	protected $ar_having				= array();
-	protected $ar_keys					= array();
-	protected $ar_limit					= FALSE;
-	protected $ar_offset				= FALSE;
-	protected $ar_order					= FALSE;
-	protected $ar_orderby				= array();
-	protected $ar_set					= array();
-	protected $ar_wherein				= array();
+	protected $ar_select			= array();
+	protected $ar_distinct			= FALSE;
+	protected $ar_from			= array();
+	protected $ar_join			= array();
+	protected $ar_where			= array();
+	protected $ar_like			= array();
+	protected $ar_groupby			= array();
+	protected $ar_having			= array();
+	protected $ar_keys			= array();
+	protected $ar_limit			= FALSE;
+	protected $ar_offset			= FALSE;
+	protected $ar_order			= FALSE;
+	protected $ar_orderby			= array();
+	protected $ar_set			= array();
+	protected $ar_wherein			= array();
 	protected $ar_aliased_tables		= array();
-	protected $ar_store_array			= array();
+	protected $ar_store_array		= array();
 	protected $ar_where_group_started	= FALSE;
 	protected $ar_where_group_count		= 0;
 
@@ -77,9 +77,7 @@
 	protected $ar_cache_set				= array();
 
 	protected $ar_no_escape 			= array();
-	protected $ar_cache_no_escape		= array();
-
-	// --------------------------------------------------------------------
+	protected $ar_cache_no_escape			= array();
 
 	/**
 	 * Select
@@ -113,6 +111,7 @@
 				}
 			}
 		}
+
 		return $this;
 	}
 
@@ -188,7 +187,7 @@
 	 *	select_max()
 	 *	select_min()
 	 *	select_avg()
-	 *  select_sum()
+	 *	select_sum()
 	 *
 	 * @param	string	the field
 	 * @param	string	an alias
@@ -214,7 +213,6 @@
 		}
 
 		$sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
-
 		$this->ar_select[] = $sql;
 
 		if ($this->ar_caching === TRUE)
@@ -280,30 +278,27 @@
 				{
 					$v = trim($v);
 					$this->_track_aliases($v);
-
-					$this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+					$v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
 
 					if ($this->ar_caching === TRUE)
 					{
-						$this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+						$this->ar_cache_from[] = $v;
 						$this->ar_cache_exists[] = 'from';
 					}
 				}
-
 			}
 			else
 			{
 				$val = trim($val);
 
-				// Extract any aliases that might exist.  We use this information
+				// Extract any aliases that might exist. We use this information
 				// in the _protect_identifiers to know whether to add a table prefix
 				$this->_track_aliases($val);
-
-				$this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+				$this->ar_from[] = $val = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
 
 				if ($this->ar_caching === TRUE)
 				{
-					$this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+					$this->ar_cache_from[] = $val;
 					$this->ar_cache_exists[] = 'from';
 				}
 			}
@@ -340,23 +335,19 @@
 			}
 		}
 
-		// Extract any aliases that might exist.  We use this information
+		// Extract any aliases that might exist. We use this information
 		// in the _protect_identifiers to know whether to add a table prefix
 		$this->_track_aliases($table);
 
 		// Strip apart the condition and protect the identifiers
 		if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
 		{
-			$match[1] = $this->_protect_identifiers($match[1]);
-			$match[3] = $this->_protect_identifiers($match[3]);
-
-			$cond = $match[1].$match[2].$match[3];
+			$cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
 		}
 
 		// Assemble the JOIN statement
-		$join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+		$this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
 
-		$this->ar_join[] = $join;
 		if ($this->ar_caching === TRUE)
 		{
 			$this->ar_cache_join[] = $join;
@@ -429,7 +420,7 @@
 
 		foreach ($key as $k => $v)
 		{
-			$prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
+			$prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
 
 			if (is_null($v) && ! $this->_has_operator($k))
 			{
@@ -442,7 +433,6 @@
 				if ($escape === TRUE)
 				{
 					$k = $this->_protect_identifiers($k, FALSE, $escape);
-
 					$v = ' '.$this->escape($v);
 				}
 
@@ -457,7 +447,6 @@
 			}
 
 			$this->ar_where[] = $prefix.$k.$v;
-
 			if ($this->ar_caching === TRUE)
 			{
 				$this->ar_cache_where[] = $prefix.$k.$v;
@@ -571,11 +560,9 @@
 			$this->ar_wherein[] = $this->escape($value);
 		}
 
-		$prefix = (count($this->ar_where) == 0) ? '' : $type;
+		$prefix = (count($this->ar_where) === 0) ? '' : $type;
+		$this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
 
-		$where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
-
-		$this->ar_where[] = $where_in;
 		if ($this->ar_caching === TRUE)
 		{
 			$this->ar_cache_where[] = $where_in;
@@ -679,20 +666,18 @@
 		foreach ($field as $k => $v)
 		{
 			$k = $this->_protect_identifiers($k);
-
-			$prefix = (count($this->ar_like) == 0) ? '' : $type;
-
+			$prefix = (count($this->ar_like) === 0) ? '' : $type;
 			$v = $this->escape_like_str($v);
 
-			if ($side == 'none')
+			if ($side === 'none')
 			{
 				$like_statement = $prefix." $k $not LIKE '{$v}'";
 			}
-			elseif ($side == 'before')
+			elseif ($side === 'before')
 			{
 				$like_statement = $prefix." $k $not LIKE '%{$v}'";
 			}
-			elseif ($side == 'after')
+			elseif ($side === 'after')
 			{
 				$like_statement = $prefix." $k $not LIKE '{$v}%'";
 			}
@@ -715,6 +700,7 @@
 			}
 
 		}
+
 		return $this;
 	}
 
@@ -730,13 +716,10 @@
 	public function group_start($not = '', $type = 'AND ')
 	{
 		$type = $this->_group_get_type($type);
-
 		$this->ar_where_group_started = TRUE;
+		$prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+		$this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
 
-		$prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
-		$value =  $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' (';
-
-		$this->ar_where[] = $value;
 		if ($this->ar_caching)
 		{
 			$this->ar_cache_where[] = $value;
@@ -790,16 +773,14 @@
 	 */
 	public function group_end()
 	{
-		$value = str_repeat(' ', $this->ar_where_group_count--) . ')';
+		$this->ar_where_group_started = FALSE;
+		$this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
 
-		$this->ar_where[] = $value;
 		if ($this->ar_caching)
 		{
 			$this->ar_cache_where[] = $value;
 		}
 
-		$this->ar_where_group_started = FALSE;
-
 		return $this;
 	}
 
@@ -845,15 +826,16 @@
 
 			if ($val != '')
 			{
-				$this->ar_groupby[] = $this->_protect_identifiers($val);
+				$this->ar_groupby[] = $val = $this->_protect_identifiers($val);
 
 				if ($this->ar_caching === TRUE)
 				{
-					$this->ar_cache_groupby[] = $this->_protect_identifiers($val);
+					$this->ar_cache_groupby[] = $val;
 					$this->ar_cache_exists[] = 'groupby';
 				}
 			}
 		}
+
 		return $this;
 	}
 
@@ -909,7 +891,7 @@
 
 		foreach ($key as $k => $v)
 		{
-			$prefix = (count($this->ar_having) == 0) ? '' : $type;
+			$prefix = (count($this->ar_having) === 0) ? '' : $type;
 
 			if ($escape === TRUE)
 			{
@@ -949,7 +931,7 @@
 	 */
 	public function order_by($orderby, $direction = '', $escape = TRUE)
 	{
-		if (strtolower($direction) == 'random')
+		if (strtolower($direction) === 'random')
 		{
 			$orderby = ''; // Random results want or don't need a field name
 			$direction = $this->_random_keyword;
@@ -960,7 +942,7 @@
 		}
 
 
-		if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE))
+		if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
 		{
 			$temp = array();
 			foreach (explode(',', $orderby) as $part)
@@ -976,7 +958,7 @@
 
 			$orderby = implode(', ', $temp);
 		}
-		else if ($direction != $this->_random_keyword)
+		elseif ($direction != $this->_random_keyword)
 		{
 			if ($escape === TRUE)
 			{
@@ -984,9 +966,8 @@
 			}
 		}
 
-		$orderby_statement = $orderby.$direction;
+		$this->ar_orderby[] = $orderby_statement = $orderby.$direction;
 
-		$this->ar_orderby[] = $orderby_statement;
 		if ($this->ar_caching === TRUE)
 		{
 			$this->ar_cache_orderby[] = $orderby_statement;
@@ -1121,9 +1102,7 @@
 			$this->limit($limit, $offset);
 		}
 
-		$sql = $this->_compile_select();
-
-		$result = $this->query($sql);
+		$result = $this->query($this->_compile_select());
 		$this->_reset_select();
 		return $result;
 	}
@@ -1145,12 +1124,10 @@
 			$this->from($table);
 		}
 
-		$sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
-
-		$query = $this->query($sql);
+		$result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
 		$this->_reset_select();
 
-		if ($query->num_rows() == 0)
+		if ($query->num_rows() === 0)
 		{
 			return 0;
 		}
@@ -1188,9 +1165,7 @@
 			$this->limit($limit, $offset);
 		}
 
-		$sql = $this->_compile_select();
-
-		$result = $this->query($sql);
+		$result = $this->query($this->_compile_select());
 		$this->_reset_select();
 		return $result;
 	}
@@ -1213,11 +1188,11 @@
 			$this->set_insert_batch($set);
 		}
 
-		if (count($this->ar_set) == 0)
+		if (count($this->ar_set) === 0)
 		{
 			if ($this->db_debug)
 			{
-				//No valid data array.  Folds in cases where keys and values did not match up
+				// No valid data array. Folds in cases where keys and values did not match up
 				return $this->display_error('db_must_use_set');
 			}
 			return FALSE;
@@ -1227,30 +1202,19 @@
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
 		}
 
 		// Batch this baby
-		for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+		for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
 		{
-
-			$sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
-
-			//echo $sql;
-
-			$this->query($sql);
+			$this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
 		}
 
 		$this->_reset_write();
-
-
 		return TRUE;
 	}
 
@@ -1294,7 +1258,6 @@
 			else
 			{
 				$clean = array();
-
 				foreach ($row as $value)
 				{
 					$clean[] = $this->escape($value);
@@ -1398,24 +1361,16 @@
 	 */
 	protected function _validate_insert($table = '')
 	{
-		if (count($this->ar_set) == 0)
+		if (count($this->ar_set) === 0)
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_must_use_set');
-			}
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
 		}
 
 		if ($table == '')
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 		}
 		else
@@ -1444,31 +1399,22 @@
 			$this->set($set);
 		}
 
-		if (count($this->ar_set) == 0)
+		if (count($this->ar_set) === 0)
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_must_use_set');
-			}
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
 		}
 
 		if ($table == '')
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
 		}
 
 		$sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
-
 		$this->_reset_write();
 		return $this->query($sql);
 	}
@@ -1543,7 +1489,6 @@
 		}
 
 		$sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
-
 		$this->_reset_write();
 		return $this->query($sql);
 	}
@@ -1559,34 +1504,28 @@
 	 *
 	 * @access	public
 	 * @param	string	the table to update data on
-	 * @return	string
+	 * @return	bool
 	 */
 	protected function _validate_update($table = '')
 	{
 		if (count($this->ar_set) == 0)
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_must_use_set');
-			}
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
 		}
 
 		if ($table == '')
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 		}
 		else
 		{
 			$this->ar_from[0] = $table;
 		}
+
+		return TRUE;
 	}
 
 	// --------------------------------------------------------------------
@@ -1599,7 +1538,7 @@
 	 * @param	string	the table to retrieve the results from
 	 * @param	array	an associative array of update values
 	 * @param	string	the where key
-	 * @return	object
+	 * @return	bool
 	 */
 	public function update_batch($table = '', $set = NULL, $index = NULL)
 	{
@@ -1608,12 +1547,7 @@
 
 		if (is_null($index))
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_must_use_index');
-			}
-
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
 		}
 
 		if ( ! is_null($set))
@@ -1621,39 +1555,29 @@
 			$this->set_update_batch($set, $index);
 		}
 
-		if (count($this->ar_set) == 0)
+		if (count($this->ar_set) === 0)
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_must_use_set');
-			}
-
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
 		}
 
 		if ($table == '')
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
 		}
 
 		// Batch this baby
-		for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+		for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
 		{
-			$sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
-
-			$this->query($sql);
+			$this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
 		}
 
 		$this->_reset_write();
+		return TRUE;
 	}
 
 	// --------------------------------------------------------------------
@@ -1679,7 +1603,6 @@
 		{
 			$index_set = FALSE;
 			$clean = array();
-
 			foreach ($v as $k2 => $v2)
 			{
 				if ($k2 == $index)
@@ -1691,14 +1614,7 @@
 					$not[] = $k.'-'.$v;
 				}
 
-				if ($escape === FALSE)
-				{
-					$clean[$this->_protect_identifiers($k2)] = $v2;
-				}
-				else
-				{
-					$clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
-				}
+				$clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
 			}
 
 			if ($index_set == FALSE)
@@ -1728,11 +1644,7 @@
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
@@ -1743,9 +1655,7 @@
 		}
 
 		$sql = $this->_delete($table);
-
 		$this->_reset_write();
-
 		return $this->query($sql);
 	}
 
@@ -1767,11 +1677,7 @@
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
@@ -1782,9 +1688,7 @@
 		}
 
 		$sql = $this->_truncate($table);
-
 		$this->_reset_write();
-
 		return $this->query($sql);
 	}
 
@@ -1830,11 +1734,7 @@
 		{
 			if ( ! isset($this->ar_from[0]))
 			{
-				if ($this->db_debug)
-				{
-					return $this->display_error('db_must_set_table');
-				}
-				return FALSE;
+				return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
 			}
 
 			$table = $this->ar_from[0];
@@ -1864,29 +1764,18 @@
 			$this->limit($limit);
 		}
 
-		if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
+		if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
 		{
-			if ($this->db_debug)
-			{
-				return $this->display_error('db_del_must_use_where');
-			}
-
-			return FALSE;
+			return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
 		}
 
 		$sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
-
 		if ($reset_data)
 		{
 			$this->_reset_write();
 		}
 
-		if ($this->return_delete_sql === true)
-		{
-			return $sql;
-		}
-
-		return $this->query($sql);
+		return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
 	}
 
 	// --------------------------------------------------------------------
@@ -1953,13 +1842,13 @@
 		}
 
 		// if a table alias is used we can recognize it by a space
-		if (strpos($table, " ") !== FALSE)
+		if (strpos($table, ' ') !== FALSE)
 		{
 			// if the alias is written with the AS keyword, remove it
 			$table = preg_replace('/ AS /i', ' ', $table);
 
 			// Grab the alias
-			$table = trim(strrchr($table, " "));
+			$table = trim(strrchr($table, ' '));
 
 			// Store the alias, if it doesn't already exist
 			if ( ! in_array($table, $this->ar_aliased_tables))
@@ -1984,10 +1873,7 @@
 		// Combine any cached components with the current statements
 		$this->_merge_cache();
 
-		// ----------------------------------------------------------------
-
 		// Write the "select" portion of the query
-
 		if ($select_override !== FALSE)
 		{
 			$sql = $select_override;
@@ -1996,7 +1882,7 @@
 		{
 			$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
 
-			if (count($this->ar_select) == 0)
+			if (count($this->ar_select) === 0)
 			{
 				$sql .= '*';
 			}
@@ -2015,32 +1901,19 @@
 			}
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "FROM" portion of the query
-
 		if (count($this->ar_from) > 0)
 		{
-			$sql .= "\nFROM ";
-
-			$sql .= $this->_from_tables($this->ar_from);
+			$sql .= "\nFROM ".$this->_from_tables($this->ar_from);
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "JOIN" portion of the query
-
 		if (count($this->ar_join) > 0)
 		{
-			$sql .= "\n";
-
-			$sql .= implode("\n", $this->ar_join);
+			$sql .= "\n".implode("\n", $this->ar_join);
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "WHERE" portion of the query
-
 		if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
 		{
 			$sql .= "\nWHERE ";
@@ -2048,10 +1921,7 @@
 
 		$sql .= implode("\n", $this->ar_where);
 
-		// ----------------------------------------------------------------
-
 		// Write the "LIKE" portion of the query
-
 		if (count($this->ar_like) > 0)
 		{
 			if (count($this->ar_where) > 0)
@@ -2062,50 +1932,32 @@
 			$sql .= implode("\n", $this->ar_like);
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "GROUP BY" portion of the query
-
 		if (count($this->ar_groupby) > 0)
 		{
-			$sql .= "\nGROUP BY ";
-
-			$sql .= implode(', ', $this->ar_groupby);
+			$sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "HAVING" portion of the query
-
 		if (count($this->ar_having) > 0)
 		{
-			$sql .= "\nHAVING ";
-			$sql .= implode("\n", $this->ar_having);
+			$sql .= "\nHAVING ".implode("\n", $this->ar_having);
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "ORDER BY" portion of the query
-
 		if (count($this->ar_orderby) > 0)
 		{
-			$sql .= "\nORDER BY ";
-			$sql .= implode(', ', $this->ar_orderby);
-
+			$sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
 			if ($this->ar_order !== FALSE)
 			{
 				$sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
 			}
 		}
 
-		// ----------------------------------------------------------------
-
 		// Write the "LIMIT" portion of the query
-
 		if (is_numeric($this->ar_limit))
 		{
-			$sql .= "\n";
-			$sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
+			return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
 		}
 
 		return $sql;
@@ -2165,14 +2017,12 @@
 		foreach ($fields as $val)
 		{
 			// There are some built in keys we need to ignore for this conversion
-			if ($val != '_parent_name')
+			if ($val !== '_parent_name')
 			{
-
 				$i = 0;
 				foreach ($out[$val] as $data)
 				{
-					$array[$i][$val] = $data;
-					$i++;
+					$array[$i++][$val] = $data;
 				}
 			}
 		}
@@ -2247,7 +2097,7 @@
 	 */
 	protected function _merge_cache()
 	{
-		if (count($this->ar_cache_exists) == 0)
+		if (count($this->ar_cache_exists) === 0)
 		{
 			return;
 		}
@@ -2257,7 +2107,7 @@
 			$ar_variable	= 'ar_'.$val;
 			$ar_cache_var	= 'ar_cache_'.$val;
 
-			if (count($this->$ar_cache_var) == 0)
+			if (count($this->$ar_cache_var) === 0)
 			{
 				continue;
 			}
@@ -2282,7 +2132,6 @@
 	 *
 	 * Publicly-visible method to reset the AR values.
 	 *
-	 * @access	public
 	 * @return	void
 	 */
 	public function reset_query()
@@ -2319,25 +2168,24 @@
 	 */
 	protected function _reset_select()
 	{
-		$ar_reset_items = array(
-			'ar_select'			=> array(),
-			'ar_from'			=> array(),
-			'ar_join'			=> array(),
-			'ar_where'			=> array(),
-			'ar_like'			=> array(),
-			'ar_groupby'		=> array(),
-			'ar_having'			=> array(),
-			'ar_orderby'		=> array(),
-			'ar_wherein'		=> array(),
-			'ar_aliased_tables'	=> array(),
-			'ar_no_escape'		=> array(),
-			'ar_distinct'		=> FALSE,
-			'ar_limit'			=> FALSE,
-			'ar_offset'			=> FALSE,
-			'ar_order'			=> FALSE,
-		);
-
-		$this->_reset_run($ar_reset_items);
+		$this->_reset_run(array(
+					'ar_select'		=> array(),
+					'ar_from'		=> array(),
+					'ar_join'		=> array(),
+					'ar_where'		=> array(),
+					'ar_like'		=> array(),
+					'ar_groupby'		=> array(),
+					'ar_having'		=> array(),
+					'ar_orderby'		=> array(),
+					'ar_wherein'		=> array(),
+					'ar_aliased_tables'	=> array(),
+					'ar_no_escape'		=> array(),
+					'ar_distinct'		=> FALSE,
+					'ar_limit'		=> FALSE,
+					'ar_offset'		=> FALSE,
+					'ar_order'		=> FALSE
+					)
+				);
 	}
 
 	// --------------------------------------------------------------------
@@ -2351,19 +2199,19 @@
 	 */
 	protected function _reset_write()
 	{
-		$ar_reset_items = array(
-			'ar_set'		=> array(),
-			'ar_from'		=> array(),
-			'ar_where'		=> array(),
-			'ar_like'		=> array(),
-			'ar_orderby'	=> array(),
-			'ar_keys'		=> array(),
-			'ar_limit'		=> FALSE,
-			'ar_order'		=> FALSE
-		);
-
-		$this->_reset_run($ar_reset_items);
+		$this->_reset_run(array(
+					'ar_set'	=> array(),
+					'ar_from'	=> array(),
+					'ar_where'	=> array(),
+					'ar_like'	=> array(),
+					'ar_orderby'	=> array(),
+					'ar_keys'	=> array(),
+					'ar_limit'	=> FALSE,
+					'ar_order'	=> FALSE
+					)
+				);
 	}
+
 }
 
 /* End of file DB_active_rec.php */
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 1ff046c..79651fc 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Database Cache Class
  *
@@ -36,19 +34,12 @@
  */
 class CI_DB_Cache {
 
-	var $CI;
-	var $db;	// allows passing of db object so that multiple database connections and returned db objects can be supported
+	public $CI;
+	public $db;	// allows passing of db object so that multiple database connections and returned db objects can be supported
 
-	/**
-	 * Constructor
-	 *
-	 * Grabs the CI super object instance so we can access it.
-	 *
-	 */
-	function __construct(&$db)
+	public function __construct(&$db)
 	{
-		// Assign the main CI object to $this->CI
-		// and load the file helper since we use it a lot
+		// Assign the main CI object to $this->CI and load the file helper since we use it a lot
 		$this->CI =& get_instance();
 		$this->db =& $db;
 		$this->CI->load->helper('file');
@@ -59,11 +50,10 @@
 	/**
 	 * Set Cache Directory Path
 	 *
-	 * @access	public
 	 * @param	string	the path to the cache directory
 	 * @return	bool
 	 */
-	function check_path($path = '')
+	public function check_path($path = '')
 	{
 		if ($path == '')
 		{
@@ -76,7 +66,7 @@
 		}
 
 		// Add a trailing slash to the path if needed
-		$path = preg_replace("/(.+?)\/*$/", "\\1/",  $path);
+		$path = preg_replace('/(.+?)\/*$/', '\\1/',  $path);
 
 		if ( ! is_dir($path) OR ! is_really_writable($path))
 		{
@@ -96,10 +86,9 @@
 	 * The URI being requested will become the name of the cache sub-folder.
 	 * An MD5 hash of the SQL statement will become the cache file name
 	 *
-	 * @access	public
 	 * @return	string
 	 */
-	function read($sql)
+	public function read($sql)
 	{
 		if ( ! $this->check_path())
 		{
@@ -107,9 +96,7 @@
 		}
 
 		$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
 		$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
 		$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
 
 		if (FALSE === ($cachedata = read_file($filepath)))
@@ -125,10 +112,9 @@
 	/**
 	 * Write a query to a cache file
 	 *
-	 * @access	public
 	 * @return	bool
 	 */
-	function write($sql, $object)
+	public function write($sql, $object)
 	{
 		if ( ! $this->check_path())
 		{
@@ -136,11 +122,8 @@
 		}
 
 		$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
-
 		$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
-
 		$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
 		$filename = md5($sql);
 
 		if ( ! @is_dir($dir_path))
@@ -167,10 +150,9 @@
 	/**
 	 * Delete cache files within a particular directory
 	 *
-	 * @access	public
 	 * @return	bool
 	 */
-	function delete($segment_one = '', $segment_two = '')
+	public function delete($segment_one = '', $segment_two = '')
 	{
 		if ($segment_one == '')
 		{
@@ -183,7 +165,6 @@
 		}
 
 		$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
-
 		delete_files($dir_path, TRUE);
 	}
 
@@ -192,16 +173,14 @@
 	/**
 	 * Delete all existing cache files
 	 *
-	 * @access	public
 	 * @return	bool
 	 */
-	function delete_all()
+	public function delete_all()
 	{
 		delete_files($this->db->cachedir, TRUE);
 	}
 
 }
 
-
 /* End of file DB_cache.php */
-/* Location: ./system/database/DB_cache.php */
\ No newline at end of file
+/* Location: ./system/database/DB_cache.php */
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 762d18a..336e949 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -36,23 +36,17 @@
  */
 class CI_DB_forge {
 
-	var $fields			= array();
-	var $keys			= array();
-	var $primary_keys	= array();
-	var $db_char_set	=	'';
+	public $fields		= array();
+	public $keys		= array();
+	public $primary_keys	= array();
+	public $db_char_set	=	'';
 
-	/**
-	 * Constructor
-	 *
-	 * Grabs the CI super object instance so we can access it.
-	 *
-	 */
-	function __construct()
+	public function __construct()
 	{
 		// Assign the main database object to $this->db
 		$CI =& get_instance();
 		$this->db =& $CI->db;
-		log_message('debug', "Database Forge Class Initialized");
+		log_message('debug', 'Database Forge Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -60,20 +54,13 @@
 	/**
 	 * Create database
 	 *
-	 * @access	public
 	 * @param	string	the database name
 	 * @return	bool
 	 */
-	function create_database($db_name)
+	public function create_database($db_name)
 	{
 		$sql = $this->_create_database($db_name);
-
-		if (is_bool($sql))
-		{
-			return $sql;
-		}
-
-		return $this->db->query($sql);
+		return is_bool($sql) ? $sql : $this->db->query($sql);
 	}
 
 	// --------------------------------------------------------------------
@@ -81,20 +68,13 @@
 	/**
 	 * Drop database
 	 *
-	 * @access	public
 	 * @param	string	the database name
 	 * @return	bool
 	 */
-	function drop_database($db_name)
+	public function drop_database($db_name)
 	{
 		$sql = $this->_drop_database($db_name);
-
-		if (is_bool($sql))
-		{
-			return $sql;
-		}
-
-		return $this->db->query($sql);
+		return is_bool($sql) ? $sql : $this->db->query($sql);
 	}
 
 	// --------------------------------------------------------------------
@@ -152,7 +132,7 @@
 
 		if (is_string($field))
 		{
-			if ($field == 'id')
+			if ($field === 'id')
 			{
 				$this->add_field(array(
 					'id' => array(
@@ -178,7 +158,7 @@
 		{
 			$this->fields = array_merge($this->fields, $field);
 		}
-		
+
 		return $this;
 	}
 
@@ -197,21 +177,14 @@
 			show_error('A table name is required for that operation.');
 		}
 
-		if (count($this->fields) == 0)
+		if (count($this->fields) === 0)
 		{
 			show_error('Field information is required.');
 		}
 
 		$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
-
 		$this->_reset();
-
-		if (is_bool($sql))
-		{
-			return $sql;
-		}
-
-		return $this->db->query($sql);
+		return is_bool($sql) ? $sql : $this->db->query($sql);
 	}
 
 	// --------------------------------------------------------------------
@@ -225,13 +198,7 @@
 	public function drop_table($table_name)
 	{
 		$sql = $this->_drop_table($this->db->dbprefix.$table_name);
-
-		if (is_bool($sql))
-		{
-			return $sql;
-		}
-
-		return $this->db->query($sql);
+		return is_bool($sql) ? $sql : $this->db->query($sql);
 	}
 
 	// --------------------------------------------------------------------
@@ -250,8 +217,7 @@
 			show_error('A table name is required for that operation.');
 		}
 
-		$sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name);
-		return $this->db->query($sql);
+		return $this->db->query($this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name));
 	}
 
 	// --------------------------------------------------------------------
@@ -273,8 +239,7 @@
 
 		// add field info into field array, but we can only do one at a time
 		// so we cycle through
-
-		foreach ($field as $k => $v)
+		foreach (array_keys($field) as $k)
 		{
 			$this->add_field(array($k => $field[$k]));
 
@@ -284,7 +249,6 @@
 			}
 
 			$sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
-
 			$this->_reset();
 
 			if ($this->db->query($sql) === FALSE)
@@ -307,7 +271,6 @@
 	 */
 	public function drop_column($table = '', $column_name = '')
 	{
-
 		if ($table == '')
 		{
 			show_error('A table name is required for that operation.');
@@ -318,9 +281,7 @@
 			show_error('A column name is required for that operation.');
 		}
 
-		$sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
-
-		return $this->db->query($sql);
+		return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name));
 	}
 
 	// --------------------------------------------------------------------
@@ -342,8 +303,7 @@
 
 		// add field info into field array, but we can only do one at a time
 		// so we cycle through
-
-		foreach ($field as $k => $v)
+		foreach (array_keys($field) as $k)
 		{
 			// If no name provided, use the current name
 			if ( ! isset($field[$k]['name']))
@@ -352,14 +312,12 @@
 			}
 
 			$this->add_field(array($k => $field[$k]));
-
-			if (count($this->fields) == 0)
+			if (count($this->fields) === 0)
 			{
 				show_error('Field information is required.');
 			}
 
 			$sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
-
 			$this->_reset();
 
 			if ($this->db->query($sql) === FALSE)
@@ -382,12 +340,10 @@
 	 */
 	protected function _reset()
 	{
-		$this->fields		= array();
-		$this->keys			= array();
-		$this->primary_keys	= array();
+		$this->fields = $this->keys = $this->primary_keys = array();
 	}
 
 }
 
 /* End of file DB_forge.php */
-/* Location: ./system/database/DB_forge.php */
\ No newline at end of file
+/* Location: ./system/database/DB_forge.php */
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index c4ed20b..7304432 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Database Result Class
  *
@@ -40,27 +38,25 @@
  */
 class CI_DB_result {
 
-	var $conn_id				= NULL;
-	var $result_id				= NULL;
-	var $result_array			= array();
-	var $result_object			= array();
-	var $custom_result_object	= array();
-	var $current_row			= 0;
-	var $num_rows				= 0;
-	var $row_data				= NULL;
-
+	public $conn_id				= NULL;
+	public $result_id			= NULL;
+	public $result_array			= array();
+	public $result_object			= array();
+	public $custom_result_object		= array();
+	public $current_row			= 0;
+	public $num_rows			= 0;
+	public $row_data			= NULL;
 
 	/**
 	 * Query result.  Acts as a wrapper function for the following functions.
 	 *
-	 * @access	public
 	 * @param	string	can be "object" or "array"
 	 * @return	mixed	either a result object or array
 	 */
 	public function result($type = 'object')
 	{
-		if ($type == 'array') return $this->result_array();
-		else if ($type == 'object') return $this->result_object();
+		if ($type === 'array') return $this->result_array();
+		elseif ($type === 'object') return $this->result_object();
 		else return $this->custom_result_object($type);
 	}
 
@@ -69,8 +65,8 @@
 	/**
 	 * Custom query result.
 	 *
-	 * @param class_name A string that represents the type of object you want back
-	 * @return array of objects
+	 * @param	string	A string that represents the type of object you want back
+	 * @return	array	of objects
 	 */
 	public function custom_result_object($class_name)
 	{
@@ -91,7 +87,6 @@
 		while ($row = $this->_fetch_object())
 		{
 			$object = new $class_name();
-
 			foreach ($row as $key => $value)
 			{
 				$object->$key = $value;
@@ -109,7 +104,6 @@
 	/**
 	 * Query result.  "object" version.
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function result_object()
@@ -141,7 +135,6 @@
 	/**
 	 * Query result.  "array" version.
 	 *
-	 * @access	public
 	 * @return	array
 	 */
 	public function result_array()
@@ -173,7 +166,6 @@
 	/**
 	 * Query result.  Acts as a wrapper function for the following functions.
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	string	can be "object" or "array"
 	 * @return	mixed	either a result object or array
@@ -197,8 +189,8 @@
 			$n = 0;
 		}
 
-		if ($type == 'object') return $this->row_object($n);
-		else if ($type == 'array') return $this->row_array($n);
+		if ($type === 'object') return $this->row_object($n);
+		elseif ($type === 'array') return $this->row_array($n);
 		else return $this->custom_row_object($n, $type);
 	}
 
@@ -207,8 +199,7 @@
 	/**
 	 * Assigns an item into a particular column slot
 	 *
-	 * @access	public
-	 * @return	object
+	 * @return	void
 	 */
 	public function set_row($key, $value = NULL)
 	{
@@ -224,7 +215,6 @@
 			{
 				$this->row_data[$k] = $v;
 			}
-
 			return;
 		}
 
@@ -239,14 +229,12 @@
 	/**
 	 * Returns a single result row - custom object version
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function custom_row_object($n, $type)
 	{
 		$result = $this->custom_result_object($type);
-
-		if (count($result) == 0)
+		if (count($result) === 0)
 		{
 			return $result;
 		}
@@ -262,14 +250,12 @@
 	/**
 	 * Returns a single result row - object version
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function row_object($n = 0)
 	{
 		$result = $this->result_object();
-
-		if (count($result) == 0)
+		if (count($result) === 0)
 		{
 			return $result;
 		}
@@ -287,14 +273,12 @@
 	/**
 	 * Returns a single result row - array version
 	 *
-	 * @access	public
 	 * @return	array
 	 */
 	public function row_array($n = 0)
 	{
 		$result = $this->result_array();
-
-		if (count($result) == 0)
+		if (count($result) === 0)
 		{
 			return $result;
 		}
@@ -313,18 +297,12 @@
 	/**
 	 * Returns the "first" row
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function first_row($type = 'object')
 	{
 		$result = $this->result($type);
-
-		if (count($result) == 0)
-		{
-			return $result;
-		}
-		return $result[0];
+		return (count($result) === 0) ? $result : $result[0];
 	}
 
 	// --------------------------------------------------------------------
@@ -332,18 +310,12 @@
 	/**
 	 * Returns the "last" row
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function last_row($type = 'object')
 	{
 		$result = $this->result($type);
-
-		if (count($result) == 0)
-		{
-			return $result;
-		}
-		return $result[count($result) -1];
+		return (count($result) === 0) ? $result : $result[count($result) - 1];
 	}
 
 	// --------------------------------------------------------------------
@@ -351,14 +323,12 @@
 	/**
 	 * Returns the "next" row
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function next_row($type = 'object')
 	{
 		$result = $this->result($type);
-
-		if (count($result) == 0)
+		if (count($result) === 0)
 		{
 			return $result;
 		}
@@ -376,14 +346,12 @@
 	/**
 	 * Returns the "previous" row
 	 *
-	 * @access	public
 	 * @return	object
 	 */
 	public function previous_row($type = 'object')
 	{
 		$result = $this->result($type);
-
-		if (count($result) == 0)
+		if (count($result) === 0)
 		{
 			return $result;
 		}
@@ -416,7 +384,6 @@
 	protected function _fetch_object() { return array(); }
 
 }
-// END DB_result class
 
 /* End of file DB_result.php */
 /* Location: ./system/database/DB_result.php */
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 8db4f3b..4c881d8 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Database Utility Class
  *
@@ -36,22 +34,15 @@
  */
 class CI_DB_utility extends CI_DB_forge {
 
-	var $db;
-	var $data_cache		= array();
+	public $db;
+	public $data_cache		= array();
 
-	/**
-	 * Constructor
-	 *
-	 * Grabs the CI super object instance so we can access it.
-	 *
-	 */
-	function __construct()
+	public function __construct()
 	{
 		// Assign the main database object to $this->db
 		$CI =& get_instance();
 		$this->db =& $CI->db;
-
-		log_message('debug', "Database Utility Class Initialized");
+		log_message('debug', 'Database Utility Class Initialized');
 	}
 
 	// --------------------------------------------------------------------
@@ -59,10 +50,9 @@
 	/**
 	 * List databases
 	 *
-	 * @access	public
 	 * @return	bool
 	 */
-	function list_databases()
+	public function list_databases()
 	{
 		// Is there a cached result?
 		if (isset($this->data_cache['db_names']))
@@ -80,8 +70,7 @@
 			}
 		}
 
-		$this->data_cache['db_names'] = $dbs;
-		return $this->data_cache['db_names'];
+		return $this->data_cache['db_names'] = $dbs;
 	}
 
 	// --------------------------------------------------------------------
@@ -89,11 +78,10 @@
 	/**
 	 * Determine if a particular database exists
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	boolean
 	 */
-	function database_exists($database_name)
+	public function database_exists($database_name)
 	{
 		// Some databases won't have access to the list_databases() function, so
 		// this is intended to allow them to override with their own functions as
@@ -114,17 +102,17 @@
 	/**
 	 * Optimize Table
 	 *
-	 * @access	public
 	 * @param	string	the table name
 	 * @return	bool
 	 */
-	function optimize_table($table_name)
+	public function optimize_table($table_name)
 	{
 		$sql = $this->_optimize_table($table_name);
 
 		if (is_bool($sql))
 		{
-				show_error('db_must_use_set');
+			show_error('db_must_use_set');
+			return FALSE;
 		}
 
 		$query = $this->db->query($sql);
@@ -140,10 +128,9 @@
 	/**
 	 * Optimize Database
 	 *
-	 * @access	public
 	 * @return	array
 	 */
-	function optimize_database()
+	public function optimize_database()
 	{
 		$result = array();
 		foreach ($this->db->list_tables() as $table_name)
@@ -177,11 +164,10 @@
 	/**
 	 * Repair Table
 	 *
-	 * @access	public
 	 * @param	string	the table name
 	 * @return	bool
 	 */
-	function repair_table($table_name)
+	public function repair_table($table_name)
 	{
 		$sql = $this->_repair_table($table_name);
 
@@ -203,14 +189,13 @@
 	/**
 	 * Generate CSV from a query result object
 	 *
-	 * @access	public
 	 * @param	object	The query result object
 	 * @param	string	The delimiter - comma by default
 	 * @param	string	The newline character - \n by default
 	 * @param	string	The enclosure - double quote by default
 	 * @return	string
 	 */
-	function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"')
+	public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
 	{
 		if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
 		{
@@ -218,15 +203,13 @@
 		}
 
 		$out = '';
-
 		// First generate the headings from the table column names
 		foreach ($query->list_fields() as $name)
 		{
 			$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
 		}
 
-		$out = rtrim($out);
-		$out .= $newline;
+		$out = rtrim($out).$newline;
 
 		// Next blast through the result array and build out the rows
 		foreach ($query->result_array() as $row)
@@ -235,8 +218,7 @@
 			{
 				$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim;
 			}
-			$out = rtrim($out);
-			$out .= $newline;
+			$out = rtrim($out).$newline;
 		}
 
 		return $out;
@@ -247,12 +229,11 @@
 	/**
 	 * Generate XML data from a query result object
 	 *
-	 * @access	public
 	 * @param	object	The query result object
 	 * @param	array	Any preferences
 	 * @return	string
 	 */
-	function xml_from_result($query, $params = array())
+	public function xml_from_result($query, $params = array())
 	{
 		if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
 		{
@@ -280,16 +261,14 @@
 		foreach ($query->result_array() as $row)
 		{
 			$xml .= $tab."<{$element}>".$newline;
-
 			foreach ($row as $key => $val)
 			{
 				$xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline;
 			}
 			$xml .= $tab."</{$element}>".$newline;
 		}
-		$xml .= "</$root>".$newline;
 
-		return $xml;
+		return $xml .= "</$root>".$newline;
 	}
 
 	// --------------------------------------------------------------------
@@ -297,10 +276,9 @@
 	/**
 	 * Database Backup
 	 *
-	 * @access	public
 	 * @return	void
 	 */
-	function backup($params = array())
+	public function backup($params = array())
 	{
 		// If the parameters have not been submitted as an
 		// array then we know that it is simply the table
@@ -314,14 +292,14 @@
 
 		// Set up our default preferences
 		$prefs = array(
-							'tables'		=> array(),
-							'ignore'		=> array(),
-							'filename'		=> '',
-							'format'		=> 'gzip', // gzip, zip, txt
-							'add_drop'		=> TRUE,
-							'add_insert'	=> TRUE,
-							'newline'		=> "\n"
-						);
+				'tables'		=> array(),
+				'ignore'		=> array(),
+				'filename'		=> '',
+				'format'		=> 'gzip', // gzip, zip, txt
+				'add_drop'		=> TRUE,
+				'add_insert'		=> TRUE,
+				'newline'		=> "\n"
+			);
 
 		// Did the user submit any preferences? If so set them....
 		if (count($params) > 0)
@@ -335,29 +313,23 @@
 			}
 		}
 
-		// ------------------------------------------------------
-
 		// Are we backing up a complete database or individual tables?
 		// If no table names were submitted we'll fetch the entire table list
-		if (count($prefs['tables']) == 0)
+		if (count($prefs['tables']) === 0)
 		{
 			$prefs['tables'] = $this->db->list_tables();
 		}
 
-		// ------------------------------------------------------
-
 		// Validate the format
 		if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
 		{
 			$prefs['format'] = 'txt';
 		}
 
-		// ------------------------------------------------------
-
-		// Is the encoder supported?  If not, we'll either issue an
+		// Is the encoder supported? If not, we'll either issue an
 		// error or use plain text depending on the debug settings
-		if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode'))
-		OR ($prefs['format'] == 'zip'  AND ! @function_exists('gzcompress')))
+		if (($prefs['format'] === 'gzip' AND ! @function_exists('gzencode'))
+			OR ($prefs['format'] === 'zip'  AND ! @function_exists('gzcompress')))
 		{
 			if ($this->db->db_debug)
 			{
@@ -367,60 +339,49 @@
 			$prefs['format'] = 'txt';
 		}
 
-		// ------------------------------------------------------
-
-		// Set the filename if not provided - Only needed with Zip files
-		if ($prefs['filename'] == '' AND $prefs['format'] == 'zip')
-		{
-			$prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database;
-			$prefs['filename'] .= '_'.date('Y-m-d_H-i', time());
-		}
-
-		// ------------------------------------------------------
-
-		// Was a Gzip file requested?
-		if ($prefs['format'] == 'gzip')
-		{
-			return gzencode($this->_backup($prefs));
-		}
-
-		// ------------------------------------------------------
-
-		// Was a text file requested?
-		if ($prefs['format'] == 'txt')
-		{
-			return $this->_backup($prefs);
-		}
-
-		// ------------------------------------------------------
-
 		// Was a Zip file requested?
-		if ($prefs['format'] == 'zip')
+		if ($prefs['format'] === 'zip')
 		{
-			// If they included the .zip file extension we'll remove it
-			if (preg_match("|.+?\.zip$|", $prefs['filename']))
+			// Set the filename if not provided (only needed with Zip files)
+			if ($prefs['filename'] == '')
 			{
-				$prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+				$prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
+							.date('Y-m-d_H-i', time()).'.sql';
 			}
-
-			// Tack on the ".sql" file extension if needed
-			if ( ! preg_match("|.+?\.sql$|", $prefs['filename']))
+			else
 			{
-				$prefs['filename'] .= '.sql';
+				// If they included the .zip file extension we'll remove it
+				if (preg_match('|.+?\.zip$|', $prefs['filename']))
+				{
+					$prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
+				}
+
+				// Tack on the ".sql" file extension if needed
+				if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
+				{
+					$prefs['filename'] .= '.sql';
+				}
 			}
 
 			// Load the Zip class and output it
-
 			$CI =& get_instance();
 			$CI->load->library('zip');
 			$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
 			return $CI->zip->get_zip();
 		}
+		elseif ($prefs['format'] == 'txt') // Was a text file requested?
+		{
+			return $this->_backup($prefs);
+		}
+		elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
+		{
+			return gzencode($this->_backup($prefs));
+		}
 
+		return;
 	}
 
 }
 
-
 /* End of file DB_utility.php */
-/* Location: ./system/database/DB_utility.php */
\ No newline at end of file
+/* Location: ./system/database/DB_utility.php */
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index f81c462..c49348e 100644
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -88,7 +88,7 @@
  *
  * @access	public
  * @param	string
- * @param   string
+ * @param	string
  * @return	string
  */
 if ( ! function_exists('entity_decode'))
@@ -101,4 +101,4 @@
 }
 
 /* End of file typography_helper.php */
-/* Location: ./system/helpers/typography_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/typography_helper.php */
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
old mode 100755
new mode 100644
index c630ebe..2cbcd9d
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -62,7 +62,7 @@
 
 /**
  * Base URL
- * 
+ *
  * Create a local URL based on your basepath.
  * Segments can be passed in as a string or an array, same as site_url
  * or a URL to a file can be passed in, e.g. to an image file.
@@ -198,7 +198,6 @@
 	function anchor_popup($uri = '', $title = '', $attributes = FALSE)
 	{
 		$title = (string) $title;
-
 		$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
 
 		if ($title == '')
@@ -248,14 +247,12 @@
 	{
 		$title = (string) $title;
 
-		if ($title == "")
+		if ($title == '')
 		{
 			$title = $email;
 		}
 
-		$attributes = _parse_attributes($attributes);
-
-		return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
+		return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
 	}
 }
 
@@ -278,19 +275,16 @@
 	{
 		$title = (string) $title;
 
-		if ($title == "")
+		if ($title == '')
 		{
 			$title = $email;
 		}
 
-		for ($i = 0; $i < 16; $i++)
-		{
-			$x[] = substr('<a href="mailto:', $i, 1);
-		}
+		$x = str_split('<a href="mailto:', 1);
 
-		for ($i = 0; $i < strlen($email); $i++)
+		for ($i = 0, $l = strlen($email); $i < $l; $i++)
 		{
-			$x[] = "|".ord(substr($email, $i, 1));
+			$x[] = '|'.ord($email[$i]);
 		}
 
 		$x[] = '"';
@@ -302,18 +296,18 @@
 				foreach ($attributes as $key => $val)
 				{
 					$x[] =  ' '.$key.'="';
-					for ($i = 0; $i < strlen($val); $i++)
+					for ($i = 0, $l = strlen($val); $i < $l; $i++)
 					{
-						$x[] = "|".ord(substr($val, $i, 1));
+						$x[] = '|'.ord($val[$i]);
 					}
 					$x[] = '"';
 				}
 			}
 			else
 			{
-				for ($i = 0; $i < strlen($attributes); $i++)
+				for ($i = 0, $l = strlen($attributes); $i < $l; $i++)
 				{
-					$x[] = substr($attributes, $i, 1);
+					$x[] = $attributes[$i];
 				}
 			}
 		}
@@ -321,26 +315,28 @@
 		$x[] = '>';
 
 		$temp = array();
-		for ($i = 0; $i < strlen($title); $i++)
+		for ($i = 0, $l = strlen($title); $i < $l; $i++)
 		{
 			$ordinal = ord($title[$i]);
 
 			if ($ordinal < 128)
 			{
-				$x[] = "|".$ordinal;
+				$x[] = '|'.$ordinal;
 			}
 			else
 			{
-				if (count($temp) == 0)
+				if (count($temp) === 0)
 				{
 					$count = ($ordinal < 224) ? 2 : 3;
 				}
 
 				$temp[] = $ordinal;
-				if (count($temp) == $count)
+				if (count($temp) === $count)
 				{
-					$number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
-					$x[] = "|".$number;
+					$number = ($count === 3)
+							? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64)
+							: (($temp[0] % 32) * 64) + ($temp[1] % 64);
+					$x[] = '|'.$number;
 					$count = 1;
 					$temp = array();
 				}
@@ -356,8 +352,7 @@
 	//<![CDATA[
 	var l=new Array();
 	<?php
-	$i = 0;
-	foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
+	for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[<?php echo $i; ?>]='<?php echo $x[$i]; ?>';<?php } ?>
 
 	for (var i = l.length-1; i >= 0; i=i-1){
 	if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
@@ -391,49 +386,46 @@
 {
 	function auto_link($str, $type = 'both', $popup = FALSE)
 	{
-		if ($type != 'email')
+		if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches))
 		{
-			if (preg_match_all("#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
-			{
-				$pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
+			$pop = ($popup) ? ' target="_blank" ' : '';
 
-				for ($i = 0; $i < count($matches['0']); $i++)
+			for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
+			{
+				if (preg_match('|\.$|', $matches[6][$i]))
+				{
+					$period = '.';
+					$matches[6][$i] = substr($matches[6][$i], 0, -1);
+				}
+				else
 				{
 					$period = '';
-					if (preg_match("|\.$|", $matches['6'][$i]))
-					{
-						$period = '.';
-						$matches['6'][$i] = substr($matches['6'][$i], 0, -1);
-					}
-
-					$str = str_replace($matches['0'][$i],
-										$matches['1'][$i].'<a href="http'.
-										$matches['4'][$i].'://'.
-										$matches['5'][$i].
-										$matches['6'][$i].'"'.$pop.'>http'.
-										$matches['4'][$i].'://'.
-										$matches['5'][$i].
-										$matches['6'][$i].'</a>'.
-										$period, $str);
 				}
+
+				$str = str_replace($matches[0][$i],
+							$matches[1][$i].'<a href="http'.$matches[4][$i].'://'
+								.$matches[5][$i].$matches[6][$i].'"'.$pop.'>http'
+								.$matches[4][$i].'://'.$matches[5][$i]
+								.$matches[6][$i].'</a>'.$period,
+							$str);
 			}
 		}
 
-		if ($type != 'url')
+		if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches))
 		{
-			if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
+			for ($i = 0, $c = count($matches); $i < $c; $i++)
 			{
-				for ($i = 0; $i < count($matches['0']); $i++)
+				if (preg_match('|\.$|', $matches[3][$i]))
+				{
+					$period = '.';
+					$matches[3][$i] = substr($matches[3][$i], 0, -1);
+				}
+				else
 				{
 					$period = '';
-					if (preg_match("|\.$|", $matches['3'][$i]))
-					{
-						$period = '.';
-						$matches['3'][$i] = substr($matches['3'][$i], 0, -1);
-					}
-
-					$str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
 				}
+
+				$str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str);
 			}
 		}
 
@@ -456,7 +448,7 @@
 {
 	function prep_url($str = '')
 	{
-		if ($str == 'http://' OR $str == '')
+		if ($str === 'http://' OR $str == '')
 		{
 			return '';
 		}
@@ -465,7 +457,7 @@
 
 		if ( ! $url OR ! isset($url['scheme']))
 		{
-			$str = 'http://'.$str;
+			return 'http://'.$str;
 		}
 
 		return $str;
@@ -490,7 +482,7 @@
 {
 	function url_title($str, $separator = 'dash', $lowercase = FALSE)
 	{
-		if ($separator == 'dash')
+		if ($separator === 'dash')
 		{
 			$search		= '_';
 			$replace	= '-';
@@ -513,10 +505,9 @@
 					);
 
 		$str = strip_tags($str);
-
 		foreach ($trans as $key => $val)
 		{
-			$str = preg_replace("#".$key."#i", $val, $str);
+			$str = preg_replace('#'.$key.'#i', $val, $str);
 		}
 
 		if ($lowercase === TRUE)
@@ -552,16 +543,18 @@
 		}
 
 		// IIS environment likely? Use 'refresh' for better compatibility
-		if (DIRECTORY_SEPARATOR != '/' && $method == 'auto')
+		if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto')
 		{
 			$method = 'refresh';
 		}
 
 		switch($method)
 		{
-			case 'refresh'	: header("Refresh:0;url=".$uri);
+			case 'refresh':
+				header('Refresh:0;url='.$uri);
 				break;
-			default			: header("Location: ".$uri, TRUE, $http_response_code);
+			default:
+				header('Location: '.$uri, TRUE, $http_response_code);
 				break;
 		}
 		exit;
@@ -604,13 +597,12 @@
 
 		if ($javascript == TRUE AND $att != '')
 		{
-			$att = substr($att, 0, -1);
+			return substr($att, 0, -1);
 		}
 
 		return $att;
 	}
 }
 
-
 /* End of file url_helper.php */
-/* Location: ./system/helpers/url_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/url_helper.php */
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php
index b38dab4..5242193 100644
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -56,28 +56,26 @@
 		// ampersands won't get messed up
 		$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
 
-		if ($protect_all === TRUE)
+		if ($protect_all == TRUE)
 		{
-			$str = preg_replace("/&(\w+);/",  "$temp\\1;", $str);
+			$str = preg_replace('/&(\w+);/', "$temp\\1;", $str);
 		}
 
-		$str = str_replace(array("&","<",">","\"", "'", "-"),
-							array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
-							$str);
+		$str = str_replace(array('&', '<', '>', '"', "'", '-'),
+					array('&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'),
+					$str);
 
 		// Decode the temp markers back to entities
-		$str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
+		$str = preg_replace('/$temp(\d+);/', '&#\\1;', $str);
 
-		if ($protect_all === TRUE)
+		if ($protect_all == TRUE)
 		{
-			$str = preg_replace("/$temp(\w+);/","&\\1;", $str);
+			return preg_replace("/$temp(\w+);/", '&\\1;', $str);
 		}
 
 		return $str;
 	}
 }
 
-// ------------------------------------------------------------------------
-
 /* End of file xml_helper.php */
-/* Location: ./system/helpers/xml_helper.php */
\ No newline at end of file
+/* Location: ./system/helpers/xml_helper.php */
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index c86224f..dc7d362 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -392,7 +392,7 @@
 	 */
 	public function resize()
 	{
-		$protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
+		$protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
 		return $this->$protocol('resize');
 	}
 
@@ -408,7 +408,7 @@
 	 */
 	public function crop()
 	{
-		$protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
+		$protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
 		return $this->$protocol('crop');
 	}
 
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 763f58b..d9eca7f 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -31,6 +31,8 @@
    -  Added application/xml for xml and application/xml, text/xsl for xsl in mimes.php.
    -  Changed logger to only chmod when file is first created.
    -  Removed previously deprecated SHA1 Library.
+   -  Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php.
+      Only entries in ``$autoload['libraries']`` are auto-loaded now.
 
 -  Helpers
 
@@ -63,13 +65,14 @@
 	    if they are set manually after initialization.
    -  Minor speed optimizations and method & property visibility declarations in the Calendar Library.
    -  Removed SHA1 function in the :doc:`Encryption Library <libraries/encryption>`.
+   -  Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library <libraries/security>`, which makes token regeneration optional.
+
 
 -  Core
 
-   -  Changed private functions in CI_URI to protected so MY_URI can
-      override them.
+   -  Changed private functions in CI_URI to protected so MY_URI can override them.
    -  Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions).
-   -  Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars()
+   -  Added method get_vars() to CI_Loader to retrieve all variables loaded with $this->load->vars().
 
 Bug fixes for 3.0
 ------------------
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index 960485a..4c594ab 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -15,6 +15,9 @@
 your index.php file. If any modifications were made to your index.php
 they will need to be made fresh in this new one.
 
+.. note:: If you have any custom developed files in these folders please
+	make copies of them first.
+
 Step 2: Change References to the SHA Library
 ============================================
 
@@ -23,6 +26,8 @@
 
 Additionally, the `sha1()` method in the :doc:`Encryption Library <../libraries/encryption>` has been removed.
 
+Step 3: Remove $autoload['core'] from your config/autoload.php
+==============================================================
 
-.. note:: If you have any custom developed files in these folders please
-	make copies of them first.
+Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed.
+Move any entries that you might have listed there to `$autoload['libraries']` instead.
diff --git a/user_guide_src/source/libraries/security.rst b/user_guide_src/source/libraries/security.rst
index 8ee0c6e..e7d2555 100644
--- a/user_guide_src/source/libraries/security.rst
+++ b/user_guide_src/source/libraries/security.rst
@@ -85,6 +85,10 @@
 form_open() function will automatically insert a hidden csrf field in
 your forms.
 
+Tokens may be either regenerated on every submission (default) or kept the same throughout the life of the CSRF cookie. The default regeneration of tokens provides stricter security but may result in usability concerns as other tokens become invalid (back/forward navigation, multiple tabs/windows, asynchronous actions, etc). You may alter this behavior by editing the following config parameter::
+
+	$config['csrf_regeneration'] = TRUE;
+
 Select URIs can be whitelisted from csrf protection (for example API
 endpoints expecting externally POSTed content). You can add these URIs
 by editing the 'csrf_exclude_uris' config parameter::