   `:merkle-db.data/families`. Returns an updated persisted root node if any
   records remain in the tree."
   [store params root changes]
-  (if (nil? root)
+  (cond
+    ; No changes, return root as-is.
+    (empty? changes)
+      root
+
     ; Empty tree.
-    (->> changes
-         (part/partition-records store params)
-         (from-partitions store params))
-    ; Check root node type.
-    (condp = (:data/type root)
-      part/data-type
-        (if (seq changes)
-          (some->>
-            (part/update-root! store params root changes)
-            (from-partitions store params))
-          root)
-      data-type
-        (letfn [(store!  ; TODO: factor out?
-                  [node]
-                  (if (mdag/link? node)
-                    node
-                    (->> (::children node)
-                         (map store!)
-                         (relink-children)
-                         (assoc node ::children)
-                         (mdag/store-node! store nil)
-                         (::node/data))))]
-          (store! (update-index-node store params nil [root changes])))
+    (nil? root)
+      (->> changes
+           (part/partition-records store params)
+           (from-partitions store params))
+
+    ; Root is a partition node.
+    (= part/data-type (:data/type root))
+      (some->>
+        (part/update-root! store params root changes)
+        (from-partitions store params))
+
+    ; Root is an index node.
+    (= data-type (:data/type root))
+      (letfn [(store!  ; TODO: very similar to `store-index!`
+                [node]
+                (if (mdag/link? node)
+                  node
+                  (->> (::children node)
+                       (map store!)
+                       (relink-children)
+                       (assoc node ::children)
+                       (mdag/store-node! store nil)
+                       (::node/data))))]
+        (store! (update-index-node store params nil [root changes])))
+
+    :else
       (throw (ex-info (str "Unsupported index-tree node type: "
                            (pr-str (:data/type root)))
-                      {:data/type (:data/type root)})))))
+                      {:data/type (:data/type root)}))))

    (if (<= (count layer) 1)
      (first layer)
      (let [index-groups (part/partition-limited
                           (::branching-factor params)
                           layer)]
        (recur (mapv (partial store-index! store height) index-groups)
               (inc height))))))

  "Rewrite a vector of childen into numbered links."
  [children]
  (into []
        (map-indexed #(mdag/link (format "%03d" %1) %2))
        children))


