diff --git a/src/camel/camel-folder-summary.c b/src/camel/camel-folder-summary.c
index 3194538a8..c29dd45ab 100644
--- a/src/camel/camel-folder-summary.c
+++ b/src/camel/camel-folder-summary.c
@@ -207,6 +207,7 @@ folder_summary_dispose (GObject *object)
 
 	priv = CAMEL_FOLDER_SUMMARY_GET_PRIVATE (object);
 
+	printf ("   %s: %p\n", __FUNCTION__, object);
 	if (priv->timeout_handle) {
 		/* this should not happen, because the release timer
 		 * holds a reference on object */
@@ -238,6 +239,7 @@ folder_summary_finalize (GObject *object)
 	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (object);
 	CamelFolderSummaryPrivate *priv = summary->priv;
 
+	printf ("   %s: %p\n", __FUNCTION__, object);
 	g_hash_table_destroy (priv->uids);
 	remove_all_loaded (summary);
 	g_hash_table_destroy (priv->loaded_infos);
@@ -768,6 +770,7 @@ camel_folder_summary_init (CamelFolderSummary *summary)
 {
 	summary->priv = CAMEL_FOLDER_SUMMARY_GET_PRIVATE (summary);
 
+	printf ("%s: %p\n", __FUNCTION__, summary);
 	summary->priv->version = CAMEL_FOLDER_SUMMARY_VERSION;
 	summary->priv->flags = 0;
 	summary->priv->timestamp = 0;
@@ -1992,35 +1995,36 @@ camel_read_mir_callback (gpointer ref,
 	return ret;
 }
 
+typedef struct _SaveData {
+	CamelFolderSummary *summary;
+	const gchar *full_name;
+	CamelDB *cdb;
+	GError **out_error;
+} SaveData;
+
 static void
 save_to_db_cb (gpointer key,
                gpointer value,
-               gpointer data)
+               gpointer user_data)
 {
 	CamelMessageInfo *mi = value;
 	CamelFolderSummary *summary;
-	CamelStore *parent_store;
-	const gchar *full_name;
-	CamelDB *cdb;
 	CamelMIRecord *mir;
 	GString *bdata_str;
-	GError **error = data;
+	SaveData *dt = user_data;
 
-	if (!camel_message_info_get_dirty (mi))
-		return;
+	g_return_if_fail (dt != NULL);
 
 	summary = camel_message_info_ref_summary (mi);
-	if (!summary)
-		return;
-
-	full_name = camel_folder_get_full_name (summary->priv->folder);
-	parent_store = camel_folder_get_parent_store (summary->priv->folder);
-	if (!parent_store) {
-		g_clear_object (&summary);
-		return;
+	if (!summary) {
+		g_warning ("%s: Summary of message info '%s : %s' is NULL, but expected %p", G_STRFUNC, dt->full_name, camel_message_info_get_subject (mi), dt->summary);
+	} else if (summary != dt->summary) {
+		g_warning ("%s: Summary of message info '%s : %s' (%p) doesn't match expected (%p)", G_STRFUNC, dt->full_name, camel_message_info_get_subject (mi), summary, dt->summary);
 	}
+	g_clear_object (&summary);
 
-	cdb = camel_store_get_db (parent_store);
+	if (!camel_message_info_get_dirty (mi))
+		return;
 
 	mir = g_new0 (CamelMIRecord, 1);
 	bdata_str = g_string_new (NULL);
@@ -2029,7 +2033,6 @@ save_to_db_cb (gpointer key,
 		g_warning ("Failed to save message info: %s\n", camel_message_info_get_uid (mi));
 		g_string_free (bdata_str, TRUE);
 		camel_db_camel_mir_free (mir);
-		g_clear_object (&summary);
 		return;
 	}
 
@@ -2037,9 +2040,8 @@ save_to_db_cb (gpointer key,
 	mir->bdata = g_string_free (bdata_str, FALSE);
 	bdata_str = NULL;
 
-	if (camel_db_write_message_info_record (cdb, full_name, mir, error) != 0) {
+	if (camel_db_write_message_info_record (dt->cdb, dt->full_name, mir, dt->out_error) != 0) {
 		camel_db_camel_mir_free (mir);
-		g_clear_object (&summary);
 		return;
 	}
 
@@ -2049,7 +2051,6 @@ save_to_db_cb (gpointer key,
 	camel_message_info_set_dirty (mi, FALSE);
 
 	camel_db_camel_mir_free (mir);
-	g_clear_object (&summary);
 }
 
 static gint
@@ -2059,6 +2060,7 @@ save_message_infos_to_db (CamelFolderSummary *summary,
 	CamelStore *parent_store;
 	CamelDB *cdb;
 	const gchar *full_name;
+	SaveData dt;
 
 	if (is_in_memory_summary (summary))
 		return 0;
@@ -2075,9 +2077,14 @@ save_message_infos_to_db (CamelFolderSummary *summary,
 
 	camel_folder_summary_lock (summary);
 
+	dt.summary = summary;
+	dt.full_name = full_name;
+	dt.cdb = cdb;
+	dt.out_error = error;
+
 	/* Push MessageInfo-es */
 	camel_db_begin_transaction (cdb, NULL);
-	g_hash_table_foreach (summary->priv->loaded_infos, save_to_db_cb, error);
+	g_hash_table_foreach (summary->priv->loaded_infos, save_to_db_cb, &dt);
 	camel_db_end_transaction (cdb, NULL);
 
 	camel_folder_summary_unlock (summary);
