Index: gnc-tree-model-account.c
===================================================================
--- gnc-tree-model-account.c	(revision 14254)
+++ gnc-tree-model-account.c	(working copy)
@@ -84,10 +84,6 @@
 						    GtkTreeIter *iter,
     						    GtkTreeIter *child);
 
-/** Helper Functions ****************************************************/
-static void gnc_tree_model_account_set_toplevel (GncTreeModelAccount *model,
-						 Account *toplevel);
-
 /** Component Manager Callback ******************************************/
 static void gnc_tree_model_account_event_handler (QofEntity *entity,
 						  QofEventId event_type,
@@ -300,13 +296,8 @@
 	priv->book = gnc_get_current_book();
 	priv->root = group;
 
-	{
-	  Account *account;
+	priv->toplevel = xaccMallocAccount(priv->book);
 
-	  account = xaccMallocAccount(priv->book);
-	  gnc_tree_model_account_set_toplevel (model, account);
-	}
-
 	priv->event_handler_id = qof_event_register_handler
 	  ((QofEventHandler)gnc_tree_model_account_event_handler, model);
 
@@ -370,7 +361,7 @@
 	iface->iter_parent     = gnc_tree_model_account_iter_parent;
 }
 
-static guint
+static GtkTreeModelFlags
 gnc_tree_model_account_get_flags (GtkTreeModel *tree_model)
 {
 	return 0;
@@ -1228,29 +1219,6 @@
 /*             Account Tree View Root Functions             */
 /************************************************************/
 
-static gpointer
-account_row_inserted (Account *account,
-		      gpointer data)
-{
-	GtkTreePath *path;
-	GtkTreeIter iter;
-
-	ENTER("account %p (%s), model %p",
-	      account, xaccAccountGetName(account), data);
-	if (!gnc_tree_model_account_get_iter_from_account
-            (GNC_TREE_MODEL_ACCOUNT (data), account, &iter))
-	  return NULL;
-
-	path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter);
-
-	gtk_tree_model_row_inserted (GTK_TREE_MODEL (data), path, &iter);
-
-	gtk_tree_path_free (path);
-
-	LEAVE(" ");
-	return NULL;
-}
-
 /*
  * Gets the top node of the model.  This node is for a pseudo-account
  * that lives above the main level accounts in the engine.
@@ -1266,57 +1234,6 @@
 	return priv->toplevel;
 }
 
-/*
- * Add a new top node to the model.  This node is for a pseudo-account
- * that lives above the main level accounts in the engine.
- */
-static void
-gnc_tree_model_account_set_toplevel (GncTreeModelAccount *model,
-                                     Account *toplevel)
-{
-	GncTreeModelAccountPrivate *priv;
-	GtkTreePath *path;
-	gint i;
-	GtkTreeIter iter;
-
-	ENTER("model %p, toplevel %p", model, toplevel);
-	g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model));
-
-	priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
-	DEBUG("old toplevel %p", priv->toplevel);
-	if (priv->toplevel != NULL) {
-            /* CAS: this can't happen because we only set toplevel on
-             * new tree models. */
-		path = gtk_tree_path_new_first ();
-		gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
-		gtk_tree_path_free (path);
-	} else {
-            /* CAS: I think this is bogus for the same reason - we'll
-             * have no rows, so why are we emitting a bunch of
-             * "row_deleted" signals when no rows can exist? */
-		path = gtk_tree_path_new_first ();
-		for (i = 0; i < xaccGroupGetNumAccounts (priv->root); i++) {
-			gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
-		}
-		gtk_tree_path_free (path);
-	}
-
-	DEBUG("set new toplevel %p", toplevel);
-	priv->toplevel = toplevel;
-
-	if (priv->toplevel != NULL) {
-		path = gtk_tree_path_new_first ();
-		if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
-		  gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
-		gtk_tree_path_free (path);
-	}
-
-	if (priv->root != NULL) {
-		xaccGroupForEachAccount (priv->root, account_row_inserted, model, TRUE);
-	}
-	LEAVE("new toplevel %p", priv->root);
-}
-
 /************************************************************/
 /*            Account Tree View Filter Functions            */
 /************************************************************/
@@ -1425,6 +1342,13 @@
 /************************************************************/
 /*   Account Tree Model - Engine Event Handling Functions   */
 /************************************************************/
+static void
+increment_stamp(GncTreeModelAccount *model)
+{
+    do {
+        model->stamp++;
+    } while (model->stamp == 0);
+}
 
 /** This function performs common updating to the model after an
  *  account has been added or removed.  The parent entry needs to be
@@ -1454,10 +1378,6 @@
     gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL(model), path, &iter);
     gtk_tree_path_up(path);
   }
-
-  do {
-    model->stamp++;
-  } while (model->stamp == 0);
 }
 
 
@@ -1528,7 +1448,9 @@
 	DEBUG("can't generate path");
 	break;
       }
-      if (!gnc_tree_model_account_get_iter(GTK_TREE_MODEL(model), &iter, path)) {
+      increment_stamp(model);
+      if (!gnc_tree_model_account_get_iter(
+              GTK_TREE_MODEL(model), &iter, path)) {
 	DEBUG("can't generate iter");
 	break;
       }
@@ -1550,6 +1472,7 @@
       }
       gtk_tree_path_append_index (path, ed->idx);
       gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), path);
+      increment_stamp(model);
       gnc_tree_model_account_path_changed(model, path);
       break;
 
