diff --git a/core/js/js.js b/core/js/js.js
index 610950995db7003855a57acc806e1f7b246fbb3d..b7442f303ac7b44ac16fcac96ca1eb5fe4bf423d 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -88,7 +88,7 @@ var OC={
 	PERMISSION_DELETE:8,
 	PERMISSION_SHARE:16,
 	webroot:oc_webroot,
-	appswebroots:oc_appswebroots,
+	appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false,
 	currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
 	coreApps:['', 'admin','log','search','settings','core','3rdparty'],
 	/**
diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php
index 47f4b423b3e92b80b16a02f9950643baa5612a77..cb2f97738399ad5923c0a6d14f0e2cc852020565 100644
--- a/core/templates/layout.base.php
+++ b/core/templates/layout.base.php
@@ -10,7 +10,6 @@
 		<script type="text/javascript">
 			var oc_debug = <?php echo (defined('DEBUG') && DEBUG) ? 'true' : 'false'; ?>;
 			var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
-			var oc_appswebroots = <?php echo $_['apps_paths'] ?>;
 			var oc_requesttoken = '<?php echo $_['requesttoken']; ?>';
 		</script>
 		<?php foreach ($_['jsfiles'] as $jsfile): ?>
diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php
index 8395426e4e4d5917f367ba746374148dd3b60f51..5b39503474de602d1145d60455a6791948bc3eb0 100644
--- a/core/templates/layout.guest.php
+++ b/core/templates/layout.guest.php
@@ -10,7 +10,6 @@
 		<script type="text/javascript">
 			var oc_debug = <?php echo (defined('DEBUG') && DEBUG) ? 'true' : 'false'; ?>;
 			var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
-			var oc_appswebroots = <?php echo $_['apps_paths'] ?>;
 			var oc_requesttoken = '<?php echo $_['requesttoken']; ?>';
 			var datepickerFormatDate = <?php echo json_encode($l->l('jsdate', 'jsdate')) ?>;
 			var dayNames = <?php echo json_encode(array((string)$l->t('Sunday'), (string)$l->t('Monday'), (string)$l->t('Tuesday'), (string)$l->t('Wednesday'), (string)$l->t('Thursday'), (string)$l->t('Friday'), (string)$l->t('Saturday'))) ?>;
diff --git a/lib/db.php b/lib/db.php
index 74e7ca5b0e0957db219ba60f71a49e528cd1d265..fbefb13a95e0db2833de7a9ecf5c82c529fb2441 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -181,7 +181,9 @@ class OC_DB {
 			try{
 				self::$PDO=new PDO($dsn, $user, $pass, $opts);
 			}catch(PDOException $e) {
-				OC_Template::printErrorPage( 'can not connect to database, using '.$type.'. ('.$e->getMessage().')' );
+				OC_User::setUserId(null);
+				OC_Template::printErrorPage('Failed to connect to '.$type.' database. ('.$e->getMessage().')' );
+				die();
 			}
 			// We always, really always want associative arrays
 			self::$PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
@@ -277,7 +279,9 @@ class OC_DB {
 			if( PEAR::isError( self::$MDB2 )) {
 				OC_Log::write('core', self::$MDB2->getUserInfo(), OC_Log::FATAL);
 				OC_Log::write('core', self::$MDB2->getMessage(), OC_Log::FATAL);
-				OC_Template::printErrorPage( 'can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')' );
+				OC_User::setUserId(null);
+				OC_Template::printErrorPage('Failed to connect to '.$type.' database. ('.self::$MDB2->getUserInfo().')' );
+				die();
 			}
 
 			// We always, really always want associative arrays
diff --git a/lib/setup.php b/lib/setup.php
index fdd10be6824b84e90682c11a5be949188a0fb80f..424414faa6b1d253ce588b19933a92cc70d39a55 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -141,7 +141,9 @@ class OC_Setup {
 			if(count($error) == 0) {
 				OC_Appconfig::setValue('core', 'installedat', microtime(true));
 				OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
-
+				OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
+				OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
+				
 				OC_Group::createGroup('admin');
 				OC_Group::addToGroup($username, 'admin');
 				OC_User::login($username, $password);
diff --git a/lib/templatelayout.php b/lib/templatelayout.php
index 4173e008ba75754572be366478cb72309a490707..83d361999867410d618da5414c37b71ce5112eec 100644
--- a/lib/templatelayout.php
+++ b/lib/templatelayout.php
@@ -28,23 +28,16 @@ class OC_TemplateLayout extends OC_Template {
 					break;
 				}
 			}
+			$apps_paths = array();
+			foreach(OC_App::getEnabledApps() as $app) {
+				$apps_paths[$app] = OC_App::getAppWebPath($app);
+			}
+			$this->assign( 'apps_paths', str_replace('\\/', '/', json_encode($apps_paths)), false ); // Ugly unescape slashes waiting for better solution
 		} else if ($renderas == 'guest') {
 			parent::__construct('core', 'layout.guest');
 		} else {
 			parent::__construct('core', 'layout.base');
 		}
-
-		$apps_paths = array();
-		foreach(OC_App::getEnabledApps() as $app) {
-			$apps_paths[$app] = OC_App::getAppWebPath($app);
-		}
-		$this->assign( 'apps_paths', str_replace('\\/', '/', json_encode($apps_paths)), false ); // Ugly unescape slashes waiting for better solution
-
-		if (OC_Config::getValue('installed', false) && !OC_AppConfig::getValue('core', 'remote_core.css', false)) {
-			OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
-			OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
-		}
-
 		// Add the js files
 		$jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
 		$this->assign('jsfiles', array(), false);