diff --git a/libedataserverui/e-categories-dialog.c b/libedataserverui/e-categories-dialog.c
index 1f1866e..a066a4c 100644
--- a/libedataserverui/e-categories-dialog.c
+++ b/libedataserverui/e-categories-dialog.c
@@ -233,7 +233,7 @@ add_comma_sep_categories (gpointer key, gpointer value, gpointer user_data)
 	GString **str = user_data;
 
 	if (strlen ((*str)->str) > 0)
-		*str = g_string_append (*str, ", ");
+		*str = g_string_append (*str, ",");
 
 	*str = g_string_append (*str, (const gchar *) key);
 }
@@ -716,11 +716,28 @@ const gchar *
 e_categories_dialog_get_categories (ECategoriesDialog *dialog)
 {
 	GtkEntry *entry;
+	const gchar *text;
 
 	g_return_val_if_fail (E_IS_CATEGORIES_DIALOG (dialog), NULL);
 
 	entry = GTK_ENTRY (dialog->priv->categories_entry);
 
+	text = gtk_entry_get_text (entry);
+	if (text) {
+		gint len = strlen (text), old_len = len;
+
+		while (len > 0 && (text [len -1] == ' ' || text [len - 1] == ','))
+			len--;
+
+		if (old_len != len) {
+			gchar *tmp = g_strndup (text, len);
+
+			gtk_entry_set_text (entry, tmp);
+
+			g_free (tmp);
+		}
+	}
+
 	return gtk_entry_get_text (entry);
 }
 
@@ -751,7 +768,10 @@ e_categories_dialog_set_categories (ECategoriesDialog *dialog,
 	if (arr) {
 		gint i = 0;
 		while (arr[i] != NULL) {
-			g_hash_table_insert (priv->selected_categories, g_strdup (arr[i]), g_strdup (arr[i]));
+			arr[i] = g_strstrip (arr[i]);
+
+			if (arr[i][0])
+				g_hash_table_insert (priv->selected_categories, g_strdup (arr[i]), g_strdup (arr[i]));
 			i++;
 		}
 
diff --git a/libedataserverui/e-category-completion.c b/libedataserverui/e-category-completion.c
index 4a1ffb8..e0ce6fd 100644
--- a/libedataserverui/e-category-completion.c
+++ b/libedataserverui/e-category-completion.c
@@ -154,7 +154,7 @@ category_completion_complete (GtkEntryCompletion *completion,
 	/* Complete the partially typed category. */
 	gtk_editable_delete_text (editable, start_pos, end_pos);
 	gtk_editable_insert_text (editable, category, -1, &start_pos);
-	gtk_editable_insert_text (editable, ", ", 2, &start_pos);
+	gtk_editable_insert_text (editable, ",", 1, &start_pos);
 	gtk_editable_set_position (editable, start_pos);
 }
 
@@ -292,6 +292,33 @@ category_completion_update_prefix (GtkEntryCompletion *completion)
 	g_free (input);
 }
 
+static gboolean
+category_completion_sanitize_suffix (GtkEntry *entry, GdkEventFocus *event, GtkEntryCompletion *completion)
+{
+	const gchar *text;
+
+	g_return_val_if_fail (entry != NULL, FALSE);
+	g_return_val_if_fail (completion != NULL, FALSE);
+
+	text = gtk_entry_get_text (entry);
+	if (text) {
+		gint len = strlen (text), old_len = len;
+
+		while (len > 0 && (text [len -1] == ' ' || text [len - 1] == ','))
+			len--;
+
+		if (old_len != len) {
+			gchar *tmp = g_strndup (text, len);
+
+			gtk_entry_set_text (entry, tmp);
+
+			g_free (tmp);
+		}
+	}
+
+	return FALSE;
+}
+
 static void
 category_completion_track_entry (GtkEntryCompletion *completion)
 {
@@ -323,6 +350,10 @@ category_completion_track_entry (GtkEntryCompletion *completion)
 		priv->last_known_entry, "notify::text",
 		G_CALLBACK (category_completion_update_prefix), completion);
 
+	g_signal_connect (
+		priv->last_known_entry, "focus-out-event",
+		G_CALLBACK (category_completion_sanitize_suffix), completion);
+
 	category_completion_update_prefix (completion);
 }
 
