diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index bc968c5e1b..4b38919e81 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -2276,6 +2276,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
 		$db->sql_query($sql);
 	}
 
+	// Committing the transaction before updating search index
+	$db->sql_transaction('commit');
+
+	// Delete draft if post was loaded...
+	$draft_id = request_var('draft_loaded', 0);
+	if ($draft_id)
+	{
+		$sql = 'DELETE FROM ' . DRAFTS_TABLE . "
+			WHERE draft_id = $draft_id
+				AND user_id = {$user->data['user_id']}";
+		$db->sql_query($sql);
+	}
+
 	// Index message contents
 	if ($update_message && $data['enable_indexing'])
 	{
@@ -2303,16 +2316,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
 		$search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']);
 	}
 
-	// Delete draft if post was loaded...
-	$draft_id = request_var('draft_loaded', 0);
-	if ($draft_id)
-	{
-		$sql = 'DELETE FROM ' . DRAFTS_TABLE . "
-			WHERE draft_id = $draft_id
-				AND user_id = {$user->data['user_id']}";
-		$db->sql_query($sql);
-	}
-
 	// Topic Notification, do not change if moderator is changing other users posts...
 	if ($user->data['user_id'] == $poster_id)
 	{
@@ -2331,8 +2334,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
 		}
 	}
 
-	$db->sql_transaction('commit');
-
 	if ($mode == 'post' || $mode == 'reply' || $mode == 'quote')
 	{
 		// Mark this topic as posted to
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index b8b8564496..0ef71e63d4 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -311,7 +311,7 @@ class session
 				else
 				{
 					// Added logging temporarly to help debug bugs...
-					if (defined('DEBUG_EXTRA'))
+					if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS)
 					{
 						add_log('critical', 'LOG_IP_BROWSER_FORWARDED_CHECK', $u_ip, $s_ip, $u_browser, $s_browser, htmlspecialchars($u_forwarded_for), htmlspecialchars($s_forwarded_for));
 					}
@@ -1121,6 +1121,12 @@ class session
 
 		if ($key)
 		{
+			// removing "stale" keys
+			$sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
+				WHERE user_id = ' . (int) $user_id . "
+					AND key_id <> '" . $db->sql_escape(md5($key)) . "'";
+			$db->sql_query($sql);
+
 			$sql = 'UPDATE ' . SESSIONS_KEYS_TABLE . '
 				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 				WHERE user_id = ' . (int) $user_id . "
@@ -1128,6 +1134,11 @@ class session
 		}
 		else
 		{
+			// Before inserting, we will remove all previous keys. ;)
+			$sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
+				WHERE user_id = ' . (int) $user_id;
+			$db->sql_query($sql);
+
 			$sql = 'INSERT INTO ' . SESSIONS_KEYS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 		}
 		$db->sql_query($sql);
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 74ffdc8c8a..395eefc1f1 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -608,6 +608,8 @@ if (version_compare($current_version, '3.0.RC3', '<='))
 	<p><?php echo $lang['PROGRESS']; ?> :: <strong>
 
 <?php
+	flush();
+
 	// after RC3 a different utf8_clean_string function is used, this requires that
 	// the unique column username_clean is recalculated, during this recalculation
 	// duplicates might be created. Since the column has to be unique such usernames
@@ -1316,6 +1318,8 @@ add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
 // Now we purge the session table as well as all cache files
 $cache->purge();
 
+exit;
+
 ?>
 
 					</div>