diff --git a/camel/camel-db.c b/camel/camel-db.c
index 8daa300..8fa7049 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -39,6 +39,11 @@
 /* how long to wait before invoking sync on the file */
 #define SYNC_TIMEOUT_SECONDS 5
 
+#define READER_LOCK(cdb) g_static_rw_lock_reader_lock (&cdb->priv->rwlock)
+#define READER_UNLOCK(cdb) g_static_rw_lock_reader_unlock (&cdb->priv->rwlock)
+#define WRITER_LOCK(cdb) g_static_rw_lock_writer_lock (&cdb->priv->rwlock)
+#define WRITER_UNLOCK(cdb) g_static_rw_lock_writer_unlock (&cdb->priv->rwlock)
+
 static sqlite3_vfs *old_vfs = NULL;
 
 typedef struct {
@@ -351,22 +356,30 @@ init_sqlite_vfs (void)
 
 struct _CamelDBPrivate {
 	GTimer *timer;
+	GStaticRWLock rwlock;
 	gchar *file_name;
 };
 
-static GStaticRecMutex trans_lock = G_STATIC_REC_MUTEX_INIT;
+/**
+ * cdb_sql_exec 
+ * @db: 
+ * @stmt: 
+ * @error: 
+ * 
+ * Callers should hold the lock
+ **/
 
 static gint write_mir (CamelDB *cdb, const gchar *folder_name, CamelMIRecord *record, CamelException *ex, gboolean delete_old_record);
 
 static gint
-cdb_sql_exec (sqlite3 *db, const gchar * stmt, CamelException *ex)
+cdb_sql_exec (sqlite3 *db, const gchar * stmt, gint (*callback)(void*,gint,gchar**,gchar**), gpointer data, CamelException *ex)
 {
 	gchar *errmsg = NULL;
 	gint   ret = -1;
 
 	d(g_print("Camel SQL Exec:\n%s\n", stmt));
 
-	ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
+	ret = sqlite3_exec (db, stmt, callback, data, &errmsg);
 	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED || ret == -1) {
 		if (errmsg) {
 			sqlite3_free (errmsg);
@@ -422,9 +435,9 @@ camel_db_open (const gchar *path, CamelException *ex)
 
 	cdb = g_new (CamelDB, 1);
 	cdb->db = db;
-	cdb->lock = g_mutex_new ();
 	cdb->priv = g_new(CamelDBPrivate, 1);
 	cdb->priv->file_name = g_strdup(path);
+	g_static_rw_lock_init (&cdb->priv->rwlock);
 	cdb->priv->timer = NULL;
 	d(g_print ("\nDatabase succesfully opened  \n"));
 
@@ -459,7 +472,9 @@ camel_db_close (CamelDB *cdb)
 {
 	if (cdb) {
 		sqlite3_close (cdb->db);
-		g_mutex_free (cdb->lock);
+		g_static_rw_lock_free (&cdb->priv->rwlock);
+		g_free (cdb->priv->file_name);
+		g_free (cdb->priv);
 		g_free (cdb);
 		d(g_print ("\nDatabase succesfully closed \n"));
 	}
@@ -473,11 +488,11 @@ camel_db_set_collate (CamelDB *cdb, const gchar *col, const gchar *collate, Came
 		if (!cdb)
 			return 0;
 
-		g_mutex_lock (cdb->lock);
+		WRITER_LOCK (cdb);
 		d(g_print("Creating Collation %s on %s with %p\n", collate, col, (gpointer) func));
 		if (collate && func)
 			ret = sqlite3_create_collation(cdb->db, collate, SQLITE_UTF8,  NULL, func);
-		g_mutex_unlock (cdb->lock);
+		WRITER_UNLOCK (cdb);
 
 		return ret;
 }
@@ -490,12 +505,12 @@ camel_db_command (CamelDB *cdb, const gchar *stmt, CamelException *ex)
 
 		if (!cdb)
 			return TRUE;
-		g_mutex_lock (cdb->lock);
+		WRITER_LOCK (cdb);
 
 		START(stmt);
-		ret = cdb_sql_exec (cdb->db, stmt, ex);
+		ret = cdb_sql_exec (cdb->db, stmt, NULL, NULL,ex);
 		END;
-		g_mutex_unlock (cdb->lock);
+		WRITER_UNLOCK (cdb);
 
 		return ret;
 }
@@ -505,13 +520,10 @@ camel_db_begin_transaction (CamelDB *cdb, CamelException *ex)
 {
 	if (!cdb)
 		return -1;
-	if (g_getenv("SQLITE_TRANSLOCK"))
-		g_static_rec_mutex_lock (&trans_lock);
-
-	g_mutex_lock (cdb->lock);
+	WRITER_LOCK (cdb);
 	STARTTS("BEGIN");
 
-	return (cdb_sql_exec (cdb->db, "BEGIN", ex));
+	return (cdb_sql_exec (cdb->db, "BEGIN", NULL, NULL, NULL));
 }
 
 gint
@@ -521,12 +533,10 @@ camel_db_end_transaction (CamelDB *cdb, CamelException *ex)
 	if (!cdb)
 		return -1;
 
-	ret = cdb_sql_exec (cdb->db, "COMMIT", ex);
+	ret = cdb_sql_exec (cdb->db, "COMMIT", NULL, NULL, ex);
 	ENDTS;
-	g_mutex_unlock (cdb->lock);
-	if (g_getenv("SQLITE_TRANSLOCK"))
-		g_static_rec_mutex_unlock (&trans_lock);
 
+	WRITER_UNLOCK (cdb);
 	CAMEL_DB_RELEASE_SQLITE_MEMORY;
 
 	return ret;
@@ -537,10 +547,9 @@ camel_db_abort_transaction (CamelDB *cdb, CamelException *ex)
 {
 	gint ret;
 
-	ret = cdb_sql_exec (cdb->db, "ROLLBACK", ex);
-	g_mutex_unlock (cdb->lock);
-	if (g_getenv("SQLITE_TRANSLOCK"))
-		g_static_rec_mutex_unlock (&trans_lock);
+	ret = cdb_sql_exec (cdb->db, "ROLLBACK", NULL, NULL, ex);
+
+	WRITER_UNLOCK (cdb);
 	CAMEL_DB_RELEASE_SQLITE_MEMORY;
 
 	return ret;
@@ -552,7 +561,7 @@ camel_db_add_to_transaction (CamelDB *cdb, const gchar *stmt, CamelException *ex
 	if (!cdb)
 		return -1;
 
-	return (cdb_sql_exec (cdb->db, stmt, ex));
+	return (cdb_sql_exec (cdb->db, stmt, NULL, NULL, ex));
 }
 
 gint
@@ -564,24 +573,24 @@ camel_db_transaction_command (CamelDB *cdb, GSList *qry_list, CamelException *ex
 	if (!cdb)
 		return -1;
 
-	g_mutex_lock (cdb->lock);
+	WRITER_LOCK (cdb);
 	STARTTS("BEGIN");
-	ret = cdb_sql_exec (cdb->db, "BEGIN", ex);
+	ret = cdb_sql_exec (cdb->db, "BEGIN", NULL, NULL, ex);
 	if (ret)
 		goto end;
 
 	while (qry_list) {
 		query = qry_list->data;
-		ret = cdb_sql_exec (cdb->db, query, ex);
+		ret = cdb_sql_exec (cdb->db, query, NULL, NULL, ex);
 		if (ret)
 			goto end;
 		qry_list = g_slist_next (qry_list);
 	}
 
-	ret = cdb_sql_exec (cdb->db, "COMMIT", ex);
+	ret = cdb_sql_exec (cdb->db, "COMMIT", NULL, NULL, ex);
 	ENDTS;
 end:
-	g_mutex_unlock (cdb->lock);
+	WRITER_UNLOCK (cdb);
 	return ret;
 }
 
@@ -603,40 +612,19 @@ gint
 camel_db_count_message_info (CamelDB *cdb, const gchar *query, guint32 *count, CamelException *ex)
 {
 	gint ret = -1;
-	gchar *errmsg = NULL;
 
-	g_mutex_lock (cdb->lock);
+	READER_LOCK (cdb);
 
 	START(query);
-	ret = sqlite3_exec(cdb->db, query, count_cb, count, &errmsg);
-	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
-		if (errmsg) {
-			sqlite3_free (errmsg);
-			errmsg = NULL;
-		}
 
-		ret = sqlite3_exec (cdb->db, query, count_cb, count, &errmsg);
-	}
+	ret = cdb_sql_exec (cdb->db, query, count_cb, count, ex);
 
 	END;
 
-	g_mutex_unlock (cdb->lock);
+	READER_UNLOCK (cdb);
 
 	CAMEL_DB_RELEASE_SQLITE_MEMORY;
 
-	if (ret != SQLITE_OK) {
-		d(g_print ("Error in SQL SELECT statement: %s [%s]\n", query, errmsg));
-		if (ex)
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _(errmsg));
-		sqlite3_free (errmsg);
-		errmsg = NULL;
-	}
-
-	if (errmsg) {
-		sqlite3_free (errmsg);
-		errmsg = NULL;
-	}
-
 	return ret;
 }
 
@@ -763,44 +751,23 @@ camel_db_count_total_message_info (CamelDB *cdb, const gchar *table_name, guint3
 gint
 camel_db_select (CamelDB *cdb, const gchar * stmt, CamelDBSelectCB callback, gpointer data, CamelException *ex)
 {
-	gchar *errmsg = NULL;
-	/*int nrecs = 0;*/
 	gint ret = -1;
 
 	if (!cdb)
 		return ret;
 
 	d(g_print ("\n%s:\n%s \n", G_STRFUNC, stmt));
-	g_mutex_lock (cdb->lock);
+	READER_LOCK (cdb);
 
 	START(stmt);
-	ret = sqlite3_exec(cdb->db, stmt, callback, data, &errmsg);
-	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
-		if (errmsg) {
-			sqlite3_free (errmsg);
-			errmsg = NULL;
-		}
-
-		ret = sqlite3_exec (cdb->db, stmt, callback, data, &errmsg);
-	}
+	
+	ret = cdb_sql_exec (cdb->db, stmt, callback, data, ex);
 
 	END;
 
-	g_mutex_unlock (cdb->lock);
-	CAMEL_DB_RELEASE_SQLITE_MEMORY;
-
-	if (ret != SQLITE_OK) {
-		d(g_warning ("Error in select statement '%s' [%s].\n", stmt, errmsg));
-		if (ex)
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, errmsg);
-		sqlite3_free (errmsg);
-		errmsg = NULL;
-	}
+	READER_UNLOCK (cdb);
 
-	if (errmsg) {
-		sqlite3_free (errmsg);
-		errmsg = NULL;
-	}
+	CAMEL_DB_RELEASE_SQLITE_MEMORY;
 
 	return ret;
 }
diff --git a/camel/camel-db.h b/camel/camel-db.h
index 540f5da..903d3f0 100644
--- a/camel/camel-db.h
+++ b/camel/camel-db.h
@@ -20,6 +20,8 @@ typedef gint(*CamelDBCollate)(gpointer ,int,gconstpointer ,int,gconstpointer );
 
 struct _CamelDB {
 	sqlite3 *db;
+	/* this lock has been replaced with a rw lock which sits inside priv.
+	This is currently unused. Keeping it, not to break the ABI */
 	GMutex *lock;
 	CamelDBPrivate *priv;
 };
diff --git a/camel/camel-store.c b/camel/camel-store.c
index 54ccac2..7a386e8 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -163,10 +163,6 @@ camel_store_finalize (CamelObject *object)
 	if (store->cdb_r) {
 		camel_db_close (store->cdb_r);
 		store->cdb_r = NULL;
-	}
-
-	if (store->cdb_w) {
-		camel_db_close (store->cdb_w);
 		store->cdb_w = NULL;
 	}
 
@@ -266,8 +262,8 @@ construct (CamelService *service, CamelSession *session,
 
 	if (camel_exception_is_set (ex))
 		return;
-	/* This is for writing to the store */
-	store->cdb_w = camel_db_clone (store->cdb_r, ex);
+	/* keep cb_w to not break the ABI */
+	store->cdb_w = store->cdb_r;
 
 	if (camel_url_get_param(url, "filter"))
 		store->flags |= CAMEL_STORE_FILTER_INBOX;
