diff --git a/t3lib/config_default.php b/t3lib/config_default.php
index 763d5416ddc424b0ac4ac32d28b2b8ca5a7fa715..9346dc37f8fbe645b7b13f19dd6126147cf58640 100644
--- a/t3lib/config_default.php
+++ b/t3lib/config_default.php
@@ -12,110 +12,154 @@
  * @author	Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 
-if (!defined ('PATH_typo3conf')) 	die ('The configuration path was not properly defined!');
+if (!defined ('PATH_typo3conf')) {
+	die('The configuration path was not properly defined!');
+}
 
-$TYPO3_CONF_VARS = require(PATH_t3lib . 'stddb/DefaultSettings.php');
+/**
+ * Load default TYPO3_CONF_VARS
+ *
+ * @return void
+ */
+function loadDefaultTypo3ConfVars() {
+	$GLOBALS['TYPO3_CONF_VARS'] = require(PATH_t3lib . 'stddb/DefaultSettings.php');
+}
+loadDefaultTypo3ConfVars();
 
-if (TYPO3_MODE === 'BE') {
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.Components.PageTree.DataProvider',
-		PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Tree',
-		'web',
-		'user,group'
-	);
+/**
+ * Register default ExtDirect components
+ *
+ * @return void
+ */
+function registerExtDirectComponents() {
+	if (TYPO3_MODE === 'BE') {
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.Components.PageTree.DataProvider',
+			PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Tree',
+			'web',
+			'user,group'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.Components.PageTree.Commands',
-		PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Commands',
-		'web',
-		'user,group'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.Components.PageTree.Commands',
+			PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Commands',
+			'web',
+			'user,group'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.Components.PageTree.ContextMenuDataProvider',
-		PATH_t3lib . 'contextmenu/pagetree/extdirect/class.t3lib_contextmenu_pagetree_extdirect_contextmenu.php:t3lib_contextmenu_pagetree_extdirect_ContextMenu',
-		'web',
-		'user,group'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.Components.PageTree.ContextMenuDataProvider',
+			PATH_t3lib . 'contextmenu/pagetree/extdirect/class.t3lib_contextmenu_pagetree_extdirect_contextmenu.php:t3lib_contextmenu_pagetree_extdirect_ContextMenu',
+			'web',
+			'user,group'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.LiveSearchActions.ExtDirect',
-		PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch',
-		'web_list',
-		'user,group'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.LiveSearchActions.ExtDirect',
+			PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch',
+			'web_list',
+			'user,group'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.BackendUserSettings.ExtDirect',
-		PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:extDirect_DataProvider_BackendUserSettings'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.BackendUserSettings.ExtDirect',
+			PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:extDirect_DataProvider_BackendUserSettings'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.CSH.ExtDirect',
-		PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:extDirect_DataProvider_ContextHelp'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.CSH.ExtDirect',
+			PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:extDirect_DataProvider_ContextHelp'
+		);
 
-	t3lib_extMgm::registerExtDirectComponent(
-		'TYPO3.ExtDirectStateProvider.ExtDirect',
-		PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_state.php:extDirect_DataProvider_State'
-	);
+		t3lib_extMgm::registerExtDirectComponent(
+			'TYPO3.ExtDirectStateProvider.ExtDirect',
+			PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_state.php:extDirect_DataProvider_State'
+		);
+	}
 }
+registerExtDirectComponents();
+
 
 $T3_VAR = array();	// Initialize.
 
-	// Handle $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']. We can not set the default above
-	// because TYPO3_version is not yet defined.
-if (empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent'])) {
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent'] = 'TYPO3/' . TYPO3_version;
-}
 define('TYPO3_user_agent', 'User-Agent: '. $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
 
-// Database-variables are cleared!
-$typo_db = '';					// The database name
-$typo_db_username = '';			// The database username
-$typo_db_password = '';			// The database password
-$typo_db_host = '';				// The database host
-$typo_db_extTableDef_script = '';	// The filename of an additional script in typo3conf/-folder which is included after tables.php. Code in this script should modify the tables.php-configuration only, and this provides a good way to extend the standard-distributed tables.php file.
+/**
+ * Check typo3conf/localconf.php exists
+ *
+ * @throws RuntimeException
+ */
+function checkLocalconfExistsOrDie() {
+	if (!@is_file(PATH_typo3conf . 'localconf.php')) {
+		throw new RuntimeException('localconf.php is not found!', 1333754332);
+	}
+}
+checkLocalconfExistsOrDie();
 
-	// Include localconf.php. Use this file to configure TYPO3 for your needs and database
-if (!@is_file(PATH_typo3conf . 'localconf.php')) {
-	throw new RuntimeException('localconf.php is not found!', 1333754332);
+/**
+ * Set global database variables to empty string.
+ * Database-variables are cleared!
+ *
+ * @TODO: Figure out why we do this (security reasons with register globals?)
+ */
+function setGlobalDatabaseVariablesToEmptyString() {
+		// The database name
+	$GLOBALS['typo_db'] = '';
+		// The database username
+	$GLOBALS['typo_db_username'] = '';
+		// The database password
+	$GLOBALS['typo_db_password'] = '';
+		// The database host
+	$GLOBALS['typo_db_host'] = '';
+		// The filename of an additional script in typo3conf/-folder which is included after
+		// tables.php. Code in this script should modify the tables.php-configuration only,
+		// and this provides a good way to extend the standard-distributed tables.php file.
+	$GLOBALS['typo_db_extTableDef_script'] = '';
 }
-require(PATH_typo3conf.'localconf.php');
+setGlobalDatabaseVariablesToEmptyString();
 
+require(PATH_typo3conf . 'localconf.php');
 
+/**
+ * Define the database setup as constants
+ * and unset no longer needed global variables
+ *
+ * @return void
+ */
+function defineTypo3DatabaseConstants() {
+	define('TYPO3_db', $GLOBALS['typo_db']);
+	define('TYPO3_db_username', $GLOBALS['typo_db_username']);
+	define('TYPO3_db_password', $GLOBALS['typo_db_password']);
+	define('TYPO3_db_host', $GLOBALS['typo_db_host']);
+	define('TYPO3_extTableDef_script', $GLOBALS['typo_db_extTableDef_script']);
+
+	unset($GLOBALS['typo_db']);
+	unset($GLOBALS['typo_db_username']);
+	unset($GLOBALS['typo_db_password']);
+	unset($GLOBALS['typo_db_host']);
+	unset($GLOBALS['typo_db_extTableDef_script']);
+}
+defineTypo3DatabaseConstants();
+
+/**
+ * Initialize caching framework
+ *
+ * @return void
+ */
 function initializeCachingFramework() {
-	require_once (PATH_t3lib . 'class.t3lib_cache.php');
-	require_once (PATH_t3lib . 'cache/class.t3lib_cache_exception.php');
-	require_once (PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php');
-	require_once (PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php');
-	require_once (PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
-	require_once (PATH_t3lib . 'cache/class.t3lib_cache_factory.php');
-	require_once (PATH_t3lib . 'cache/class.t3lib_cache_manager.php');
-	require_once (PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php');
-	require_once (PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php');
-	require_once (PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php');
-	require_once (PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_phpfrontend.php');
-	require_once (PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php');
-	require_once (PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php');
-	require_once (PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_phpcapablebackend.php');
-	require_once (PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php');
-	require_once (PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php');
 	t3lib_cache::initializeCachingFramework();
 }
-
-	// The autoloader must be required BEFORE the initialization of the caching framework,
-	// because we need one method from the autoloader in t3lib_div::getClassName
-	// which will be used during the caching framework startup
-require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
-
 initializeCachingFramework();
 
-
-// *********************
-// Autoloader
-// *********************
-t3lib_autoloader::registerAutoloader();
+/**
+ * Register autoloader
+ *
+ * @return void
+ */
+function registerAutoloader() {
+	t3lib_autoloader::registerAutoloader();
+}
+registerAutoloader();
 
 /**
  * Add typo3/contrib/pear/ as first include folder in
@@ -128,8 +172,13 @@ t3lib_autoloader::registerAutoloader();
  * shipped version is loaded before any local PEAR package,
  * thus avoiding any incompatibilities with newer or older
  * versions.
+ *
+ * @return void
  */
-set_include_path(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR . get_include_path());
+function addCorePearPathToIncludePath() {
+	set_include_path(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR . get_include_path());
+}
+addCorePearPathToIncludePath();
 
 /**
  * Checking for UTF-8 in the settings since TYPO3 4.5
@@ -139,243 +188,329 @@ set_include_path(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR . get_include_pat
  *   [BE][forceCharset] is set to the charset that TYPO3 is using
  *   [SYS][setDBinit] is used to set the DB connection
  * and both settings need to be adjusted for UTF-8 in order to work properly
+ *
+ * @return void
  */
-	// Check if [BE][forceCharset] has been set in localconf.php
-if (isset($TYPO3_CONF_VARS['BE']['forceCharset'])) {
-		// die() unless we're already on UTF-8
-	if ($TYPO3_CONF_VARS['BE']['forceCharset'] != 'utf-8' && $TYPO3_CONF_VARS['BE']['forceCharset'] && TYPO3_enterInstallScript !== '1') {
-		die('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' .
-			'The configuration option $TYPO3_CONF_VARS[BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />' .
-			'You have configured the value to something different, which is not supported anymore.<br />' .
-			'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.'
-		);
-	} else {
-		unset($TYPO3_CONF_VARS['BE']['forceCharset']);
+function checkUtf8DatabaseSettingsOrDie() {
+		// Check if [BE][forceCharset] has been set in localconf.php
+	if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'])) {
+			// die() unless we're already on UTF-8
+		if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != 'utf-8' &&
+			$GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] &&
+			TYPO3_enterInstallScript !== '1'
+		) {
+			die('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' .
+				'The configuration option $GLOBALS[\'TYPO3_CONF_VARS\'][BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />' .
+				'You have configured the value to something different, which is not supported anymore.<br />' .
+				'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.'
+			);
+		} else {
+			unset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
+		}
 	}
-}
 
-if (isset($TYPO3_CONF_VARS['SYS']['setDBinit']) &&
-	$TYPO3_CONF_VARS['SYS']['setDBinit'] !== '-1' &&
-	preg_match('/SET NAMES utf8/', $TYPO3_CONF_VARS['SYS']['setDBinit']) === FALSE &&
-	TYPO3_enterInstallScript !== '1'
-) {
-		// Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
-	die('This TYPO3 installation is using the $TYPO3_CONF_VARS[\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) .
-		$TYPO3_CONF_VARS['SYS']['setDBinit'] . chr(10) . chr(10) .
-		'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) .
-		'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) .
-		'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
-} else {
-	$TYPO3_CONF_VARS['SYS']['setDBinit'] = 'SET NAMES utf8;';
+	if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) &&
+		$GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' &&
+		preg_match('/SET NAMES utf8/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE &&
+		TYPO3_enterInstallScript !== '1'
+	) {
+			// Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
+		die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) .
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) .
+			'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) .
+			'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) .
+			'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
+	} else {
+		$GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
+	}
 }
-
+checkUtf8DatabaseSettingsOrDie();
 
 
 /**
  * Parse old curl options and set new http ones instead
  *
- * @deprecated Deprecated since 4.6 - will be removed in 4.8.
+ * @TODO: This code segment must still be finished
+ * @return void
  */
-if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
-	$proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
-	/* TODO: uncomment after refactoring getUrl()
-	t3lib_div::deprecationLog(
-		'This TYPO3 installation is using the $TYPO3_CONF_VARS[\'SYS\'][\'curlProxyServer\'] property with the following value: ' .
-		$TYPO3_CONF_VARS['SYS']['curlProxyServer'] . LF . 'Please make sure to set $TYPO3_CONF_VARS[\'HTTP\'][\'proxy_host\']' .
-		' and $TYPO3_CONF_VARS[\'HTTP\'][\'proxy_port\'] instead.' . LF . 'Remove this line from your localconf.php.'
-	);*/
-}
-if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
-	$userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
-	/* TODO: uncomment after refactoring getUrl()
-	t3lib_div::deprecationLog(
-		'This TYPO3 installation is using the $TYPO3_CONF_VARS[\'SYS\'][\'curlProxyUserPass\'] property with the following value: ' .
-		$TYPO3_CONF_VARS['SYS']['curlProxyUserPass'] . LF . 'Please make sure to set $TYPO3_CONF_VARS[\'HTTP\'][\'proxy_user\']' .
-		' and $TYPO3_CONF_VARS[\'HTTP\'][\'proxy_password\'] instead.' . LF . 'Remove this line from your localconf.php.'
-	);*/
+function transferDeprecatedCurlSettings() {
+	if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
+		$proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
+		$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
+		$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
+		/* TODO: uncomment after refactoring getUrl()
+		t3lib_div::deprecationLog(
+			'This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'curlProxyServer\'] property with the following value: ' .
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] . LF . 'Please make sure to set $GLOBALS[\'TYPO3_CONF_VARS\'][\'HTTP\'][\'proxy_host\']' .
+			' and $GLOBALS['TYPO3_CONF_VARS'][\'HTTP\'][\'proxy_port\'] instead.' . LF . 'Remove this line from your localconf.php.'
+		);*/
+	}
+	if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
+		$userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
+		$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
+		$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
+		/* TODO: uncomment after refactoring getUrl()
+		t3lib_div::deprecationLog(
+			'This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'curlProxyUserPass\'] property with the following value: ' .
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] . LF . 'Please make sure to set $GLOBALS[\'TYPO3_CONF_VARS\'][\'HTTP\'][\'proxy_user\']' .
+			' and $GLOBALS['TYPO3_CONF_VARS'][\'HTTP\'][\'proxy_password\'] instead.' . LF . 'Remove this line from your localconf.php.'
+		);*/
+	}
 }
+transferDeprecatedCurlSettings();
+
 
 /**
  * Set cacheHash options
+ *
+ * @return void
  */
-$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
-	'cachedParametersWhiteList' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
-	'excludedParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
-	'requireCacheHashPresenceParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE),
-);
-if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
-	$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
-} else {
-	$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
-}
-
-
-	// ['HTTP']['proxy_auth_scheme'] can only be 'digest' or 'basic'
-$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'digest' :
-	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic';
-
-
-$timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
-if (empty($timeZone)) {
-		// time zone from the server environment (TZ env or OS query)
-	$defaultTimeZone = @date_default_timezone_get();
-	if ($defaultTimeZone !== '') {
-		$timeZone = $defaultTimeZone;
+function setCacheHashOptions() {
+	$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
+		'cachedParametersWhiteList' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
+		'excludedParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
+		'requireCacheHashPresenceParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE),
+	);
+	if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
+		$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
 	} else {
-		$timeZone = 'UTC';
-	}
-}
-	// sets the default to avoid E_WARNINGs under PHP 5.3
-date_default_timezone_set($timeZone);
-
-	// Defining the database setup as constants
-define('TYPO3_db', $typo_db);
-define('TYPO3_db_username', $typo_db_username);
-define('TYPO3_db_password', $typo_db_password);
-define('TYPO3_db_host', $typo_db_host);
-define('TYPO3_extTableDef_script', $typo_db_extTableDef_script);
-
-	// Initialize the locales handled by TYPO3
-t3lib_l10n_Locales::initialize();
-
-	// Unsetting the configured values. Use of these are deprecated.
-unset($typo_db);
-unset($typo_db_username);
-unset($typo_db_password);
-unset($typo_db_host);
-unset($typo_db_extTableDef_script);
-
-	// Based on the configuration of the image processing some options may be forced:
-if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']=0;
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']=0;
-}
-if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']='';
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']='';
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']='gif,jpg,jpeg,png';
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
-}
-if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
-
-	if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']==='gm') {
-		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
-		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
-		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
-		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
+		$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
 	}
 }
-if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
-	$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask']=$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask']?0:1;
-}
+setCacheHashOptions();
 
 
-	// Convert type of "pageNotFound_handling" setting in case it was written as a string (e.g. if edited in Install Tool)
-	// TODO: Once the Install Tool handles such data types correctly, this workaround should be removed again...
-if (!strcasecmp($TYPO3_CONF_VARS['FE']['pageNotFound_handling'], 'TRUE')) {
-	$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = TRUE;
+/**
+ * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
+ * 'digest' or 'basic' with fallback to 'basic'
+ *
+ * @return void
+ */
+function enforceCorrectProxyAuthScheme() {
+	$GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?
+		: $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic';
 }
+enforceCorrectProxyAuthScheme();
 
+/**
+ * Set default timezone
+ *
+ * @return void
+ */
+function setDefaultTimezone() {
+	$timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
+	if (empty($timeZone)) {
+			// Time zone from the server environment (TZ env or OS query)
+		$defaultTimeZone = @date_default_timezone_get();
+		if ($defaultTimeZone !== '') {
+			$timeZone = $defaultTimeZone;
+		} else {
+			$timeZone = 'UTC';
+		}
+	}
+		// Set default to avoid E_WARNINGs with PHP > 5.3
+	date_default_timezone_set($timeZone);
+}
+setDefaultTimezone();
 
-	// simple debug function which prints output immediately
-function xdebug($var = '', $debugTitle = 'xdebug') {
-		// If you wish to use the debug()-function, and it does not output something, please edit the IP mask in TYPO3_CONF_VARS
-	if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']))	return;
-	t3lib_utility_Debug::debug($var, $debugTitle);
+/**
+ * Initialize the locales handled by TYPO3
+ *
+ * @return void
+ */
+function initializeL10nLocales() {
+	t3lib_l10n_Locales::initialize();
 }
-	// Debug function which calls $GLOBALS['error'] error handler if available
-function debug($variable='', $name='*variable*', $line='*line*', $file='*file*', $recursiveDepth=3, $debugLevel=E_DEBUG) {
-		// If you wish to use the debug()-function, and it does not output something, please edit the IP mask in TYPO3_CONF_VARS
-	if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']))	return;
+initializeL10nLocales();
 
-	if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debug'))) {
-		$GLOBALS['error']->debug($variable, $name, $line, $file, $recursiveDepth, $debugLevel);
-	} else {
-		$title = ($name === '*variable*') ? '' : $name;
-		$group = ($line === '*line*') ? NULL : $line;
-		t3lib_utility_Debug::debug($variable, $title, $group);
+
+/**
+ * Based on the configuration of the image processing some options are forced
+ * to simplify configuration settings and combinations
+ *
+ * @return void
+ */
+function configureImageProcessingOptions() {
+	if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
 	}
-}
-function debugBegin() {
-	if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugBegin'))) {
-		$GLOBALS['error']->debugBegin();
+	if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
 	}
-}
-function debugEnd() {
-	if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugEnd'))) {
-		$GLOBALS['error']->debugEnd();
+	if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
+		if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']==='gm') {
+			$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
+			$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
+			$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
+			$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
+		}
+	}
+	if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
+		$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
 	}
 }
+configureImageProcessingOptions();
 
 
-	// Init services array:
-$T3_SERVICES = array();
-
-	// Error & exception handling
-$TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] = $TYPO3_CONF_VARS['SYS']['productionExceptionHandler'];
-$TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors'] = $TYPO3_CONF_VARS['SYS']['exceptionalErrors'];
+/**
+ * Convert type of "pageNotFound_handling" setting in case it was written as a
+ * string (e.g. if edited in Install Tool)
+ *
+ * @TODO: Remove, if the Install Tool handles such data types correctly
+ * @return void
+ */
+function convertPageNotFoundHandlingToBoolean() {
+	if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
+		$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
+	}
+}
+convertPageNotFoundHandlingToBoolean();
 
-	// Mail sending via Swift Mailer
-$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] = 't3lib_mail_SwiftMailerAdapter';
+/**
+ * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
+ *
+ * Note: Yes, this is possible in php! xdebug() is then a global function, even
+ * if registerGlobalDebugFunctions() is encapsulated in class scope.
+ *
+ * @return void
+ */
+function registerGlobalDebugFunctions() {
+		// Simple debug function which prints output immediately
+	function xdebug($var = '', $debugTitle = 'xdebug') {
+			// If you wish to use the debug()-function, and it does not output something,
+			// please edit the IP mask in TYPO3_CONF_VARS
+		if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
+			return;
+		}
+		t3lib_utility_Debug::debug($var, $debugTitle);
+	}
 
-	// Turn error logging on/off.
-if (($displayErrors = intval($TYPO3_CONF_VARS['SYS']['displayErrors'])) != '-1') {
-	if ($displayErrors == 2)	{	// Special value "2" enables this feature only if $TYPO3_CONF_VARS[SYS][devIPmask] matches
-		if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
-			$displayErrors = 1;
+		// Debug function which calls $GLOBALS['error'] error handler if available
+	function debug($variable = '', $name = '*variable*', $line = '*line*', $file = '*file*', $recursiveDepth = 3, $debugLevel = E_DEBUG) {
+			// If you wish to use the debug()-function, and it does not output something,
+			// please edit the IP mask in TYPO3_CONF_VARS
+		if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
+			return;
+		}
+		if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'], 'debug'))) {
+			$GLOBALS['error']->debug($variable, $name, $line, $file, $recursiveDepth, $debugLevel);
 		} else {
-			$displayErrors = 0;
+			$title = ($name === '*variable*') ? '' : $name;
+			$group = ($line === '*line*') ? NULL : $line;
+			t3lib_utility_Debug::debug($variable, $title, $group);
 		}
 	}
-	if ($displayErrors == 0) {
-		$TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
-	}
-	if ($displayErrors == 1) {
-		$TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] = $TYPO3_CONF_VARS['SYS']['debugExceptionHandler'];
-		define('TYPO3_ERRORHANDLER_MODE', 'debug');
+
+	function debugBegin() {
+		if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugBegin'))) {
+			$GLOBALS['error']->debugBegin();
+		}
 	}
 
-	@ini_set('display_errors', $displayErrors);
-} elseif (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
-		// with displayErrors = -1 (default), turn on debugging if devIPmask matches:
-	$TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] = $TYPO3_CONF_VARS['SYS']['debugExceptionHandler'];
+	function debugEnd() {
+		if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugEnd'))) {
+			$GLOBALS['error']->debugEnd();
+		}
+	}
 }
+registerGlobalDebugFunctions();
 
+	// Init services array:
+$T3_SERVICES = array();
+
+/**
+ * Mail sending via Swift Mailer
+ *
+ * @return void
+ */
+function registerSwiftMailer() {
+	$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][]
+		= 't3lib_mail_SwiftMailerAdapter';
+}
+registerSwiftMailer();
 
+/**
+ * Configure and set up exception and error handling
+ *
+ * @return void
+ */
+function configureExceptionHandling() {
+	$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
+	$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
+
+		// Turn error logging on/off.
+	if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
+			// Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
+		if ($displayErrors == 2) {
+			if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
+				$displayErrors = 1;
+			} else {
+				$displayErrors = 0;
+			}
+		}
+		if ($displayErrors == 0) {
+			$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
+		}
+		if ($displayErrors == 1) {
+			$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
+			define('TYPO3_ERRORHANDLER_MODE', 'debug');
+		}
 
-	// Set PHP memory limit depending on value of $TYPO3_CONF_VARS["SYS"]["setMemoryLimit"]
-if (intval($TYPO3_CONF_VARS['SYS']['setMemoryLimit']) > 16) {
-	@ini_set('memory_limit', intval($TYPO3_CONF_VARS['SYS']['setMemoryLimit']) . 'm');
+		@ini_set('display_errors', $displayErrors);
+	} elseif (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
+			// With displayErrors = -1 (default), turn on debugging if devIPmask matches:
+		$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
+	}
 }
+configureExceptionHandling();
 
+/**
+ * Set PHP memory limit depending on value of
+ * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
+ *
+ * @return void
+ */
+function setMemoryLimit() {
+	if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
+		@ini_set('memory_limit', intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm');
+	}
+}
+setMemoryLimit();
 
-// setting the request type so devs exactly know what type of request it is
-define('TYPO3_REQUESTTYPE_FE', 1);
-define('TYPO3_REQUESTTYPE_BE', 2);
-define('TYPO3_REQUESTTYPE_CLI', 4);
-define('TYPO3_REQUESTTYPE_AJAX', 8);
-define('TYPO3_REQUESTTYPE_INSTALL', 16);
-define('TYPO3_REQUESTTYPE',
-	(TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) |
-	(TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0) |
-	((defined('TYPO3_cliMode') && TYPO3_cliMode) ? TYPO3_REQUESTTYPE_CLI : 0) |
-	((defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) ? TYPO3_REQUESTTYPE_INSTALL : 0) |
-	($TYPO3_AJAX ? TYPO3_REQUESTTYPE_AJAX : 0)
-);
+/**
+ * Define TYPO3_REQUESTTYPE* constants
+ * so devs exactly know what type of request it is
+ *
+ * @return void
+ */
+function defineTypo3RequestTypes() {
+	define('TYPO3_REQUESTTYPE_FE', 1);
+	define('TYPO3_REQUESTTYPE_BE', 2);
+	define('TYPO3_REQUESTTYPE_CLI', 4);
+	define('TYPO3_REQUESTTYPE_AJAX', 8);
+	define('TYPO3_REQUESTTYPE_INSTALL', 16);
+	define('TYPO3_REQUESTTYPE',
+		(TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) |
+		(TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0) |
+		((defined('TYPO3_cliMode') && TYPO3_cliMode) ? TYPO3_REQUESTTYPE_CLI : 0) |
+		((defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) ? TYPO3_REQUESTTYPE_INSTALL : 0) |
+		($GLOBALS['TYPO3_AJAX'] ? TYPO3_REQUESTTYPE_AJAX : 0)
+	);
+}
+defineTypo3RequestTypes();
 
 
-// Load extensions:
+	// Load extensions:
 $TYPO3_LOADED_EXT = t3lib_extMgm::typo3_loadExtensions();
 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
-	require(PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php');
+	require(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_localconf.php');
 } else {
 	$temp_TYPO3_LOADED_EXT = $TYPO3_LOADED_EXT;
 	foreach ($temp_TYPO3_LOADED_EXT as $_EXTKEY => $temp_lEDat) {
@@ -386,60 +521,115 @@ if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
 	}
 }
 
-	// Write deprecation log if the TYPO3 instance uses deprecated XCLASS
-	// registrations via $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']
-if (count($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']) > 0) {
-	t3lib_div::deprecationLog('This installation runs with extensions that use XCLASSing by setting the XCLASS path in ext_localconf.php. This is deprecated and will be removed in TYPO3 6.2 and later. It is preferred to define XCLASSes in ext_autoload.php instead. See http://wiki.typo3.org/Autoload for more information.');
+/**
+ * Write deprecation log if the TYPO3 instance uses deprecated XCLASS
+ * registrations via $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']
+ */
+function deprecationLogForOldXclassRegistration() {
+	if (count($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']) > 0) {
+		t3lib_div::deprecationLog(
+			'This installation runs with extensions that use XCLASSing by setting the XCLASS path in ext_localconf.php. ' .
+			'This is deprecated and will be removed in TYPO3 6.2 and later. It is preferred to define XCLASSes in ' .
+			'ext_autoload.php instead. See http://wiki.typo3.org/Autoload for more information.'
+		);
+	}
 }
+deprecationLogForOldXclassRegistration();
 
-
-	// Error & Exception handling
-if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
-	if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
-			// Register an error handler for the given errorHandlerErrors
-		$errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
-			// Set errors which will be converted in an exception
-		$errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
+/**
+ * Initialize exception handling
+ *
+ * @return void
+ */
+function initializeExceptionHandling() {
+	if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
+		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
+				// Register an error handler for the given errorHandlerErrors
+			$errorHandler = t3lib_div::makeInstance(
+				$GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'],
+				$GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']
+			);
+				// Set errors which will be converted in an exception
+			$errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
+		}
+			// Instantiate the exception handler once to make sure object is registered
+			// @TODO: Figure out if this is really needed
+		t3lib_div::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
 	}
-	$exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
 }
+initializeExceptionHandling();
 
-	// Extensions may register new caches, so we set the
-	// global cache array to the manager again at this point
-$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
-
-require_once(t3lib_extMgm::extPath('lang') . 'lang.php');
 
-	// Define "TYPO3_DLOG" constant
-define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
+/**
+ * Extensions may register new caches, so we set the
+ * global cache array to the manager again at this point
+ *
+ * @return void
+ */
+function setFinalCachingFrameworkCacheConfiguration() {
+	$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+}
+setFinalCachingFrameworkCacheConfiguration();
 
-define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
-define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
+	// @TODO: Find out if we can move this to requireBaseClasses of bootstrap classes
+require_once(t3lib_extMgm::extPath('lang') . 'lang.php');
 
-	// Unsetting other reserved global variables:
-	// Those which are/can be set in "stddb/tables.php" files:
-unset($PAGES_TYPES);
-unset($TCA);
-unset($TBE_MODULES);
-unset($TBE_STYLES);
-unset($FILEICONS);
 
-	// Those set in init.php:
-unset($WEBMOUNTS);
-unset($FILEMOUNTS);
-unset($BE_USER);
+/**
+ * Define logging and exception constants
+ *
+ * @return void
+ */
+function defineLoggingAndExceptionConstants() {
+	define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
+	define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
+	define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
+}
+defineLoggingAndExceptionConstants();
 
-	// Those set otherwise:
-unset($TBE_MODULES_EXT);
-unset($TCA_DESCR);
-unset($LOCAL_LANG);
-unset($TYPO3_AJAX);
 
+/**
+ * Unsetting reserved global variables:
+ * Those which are/can be set in "stddb/tables.php" files:
+ *
+ * @return void
+ */
+function unsetReservedGlobalVariables() {
+	unset($GLOBALS['PAGES_TYPES']);
+	unset($GLOBALS['TCA']);
+	unset($GLOBALS['TBE_MODULES']);
+	unset($GLOBALS['TBE_STYLES']);
+	unset($GLOBALS['FILEICONS']);
+
+		// Those set in init.php:
+	unset($GLOBALS['WEBMOUNTS']);
+	unset($GLOBALS['FILEMOUNTS']);
+	unset($GLOBALS['BE_USER']);
+
+		// Those set otherwise:
+	unset($GLOBALS['TBE_MODULES_EXT']);
+	unset($GLOBALS['TCA_DESCR']);
+	unset($GLOBALS['LOCAL_LANG']);
+	unset($GLOBALS['TYPO3_AJAX']);
+}
+unsetReservedGlobalVariables();
 
-	// Setting some global vars:
-$EXEC_TIME = time();					// $EXEC_TIME is set so that the rest of the script has a common value for the script execution time
-$SIM_EXEC_TIME = $EXEC_TIME;			// $SIM_EXEC_TIME is set to $EXEC_TIME but can be altered later in the script if we want to simulate another execution-time when selecting from eg. a database
-$ACCESS_TIME = $EXEC_TIME - ($EXEC_TIME % 60);		// $ACCESS_TIME is a common time in minutes for access control
-$SIM_ACCESS_TIME = $ACCESS_TIME;		// if $SIM_EXEC_TIME is changed this value must be set accordingly
+/**
+ * Initialize some global time variables
+ *
+ * @return void
+ */
+function initializeGlobalTimeVariables() {
+		// $EXEC_TIME is set so that the rest of the script has a common value for the script execution time
+	$GLOBALS['EXEC_TIME'] = time();
+		// $SIM_EXEC_TIME is set to $EXEC_TIME but can be altered later in the script if we want to
+		// simulate another execution-time when selecting from eg. a database
+	$GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
+		// $ACCESS_TIME is a common time in minutes for access control
+	$GLOBALS['ACCESS_TIME'] = $GLOBALS['EXEC_TIME'] - ($GLOBALS['EXEC_TIME'] % 60);
+		// If $SIM_EXEC_TIME is changed this value must be set accordingly
+	$GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
+}
+initializeGlobalTimeVariables();
 
-?>
+?>
\ No newline at end of file
diff --git a/t3lib/stddb/DefaultSettings.php b/t3lib/stddb/DefaultSettings.php
index b5e08c73f7c94b79405b0cf68279f15e95c1ba69..bb7c798006cda120b94922f32f121ffb0eb3bf6f 100644
--- a/t3lib/stddb/DefaultSettings.php
+++ b/t3lib/stddb/DefaultSettings.php
@@ -645,7 +645,7 @@ return array(
 		'ssl_capath' => '',					// String: Directory holding multiple Certificate Authority files.
 		'ssl_local_cert' => '',				// String: Name of a file containing local certificate.
 		'ssl_passphrase' => '',				// String: Passphrase with which local certificate was encoded.
-		'userAgent' => '',					// String: Default user agent. If empty, this will be "TYPO3/4.x", while x is the current branch version. This overrides the constant <em>TYPO3_user_agent</em>.
+		'userAgent' => 'TYPO3/' . TYPO3_version,	// String: Default user agent. If empty, this will be "TYPO3/4.x", while x is the current branch version. This overrides the constant <em>TYPO3_user_agent</em>.
 	),
 	'MODS' => array(		// Backend Module Configuration (obsolete, make extension instead)
 	),
diff --git a/typo3/classes/Bootstrap/Backend.php b/typo3/classes/Bootstrap/Backend.php
index b344012492f1ac4e1f2ed4949312e7fe2cff688c..55ddc200438190c0964f6eb3371d93051e12cd1d 100644
--- a/typo3/classes/Bootstrap/Backend.php
+++ b/typo3/classes/Bootstrap/Backend.php
@@ -155,7 +155,27 @@ class Typo3_Bootstrap_Backend {
 	 */
 	public static function requireBaseClasses() {
 		require_once(PATH_t3lib . 'class.t3lib_div.php');
+
 		require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
+
+		require_once(PATH_t3lib . 'class.t3lib_cache.php');
+		require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php');
+		require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php');
+		require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php');
+		require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
+		require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php');
+		require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php');
+		require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php');
+		require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php');
+		require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php');
+		require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_phpfrontend.php');
+		require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php');
+		require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php');
+		require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_phpcapablebackend.php');
+		require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php');
+		require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php');
+
+		require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
 	}
 
 	/**