 
 (defn merge-hierarchical-maps
   [hm1 hm2]
-  (into {}
-        (doseq [[subfield value-maps] hm1]
-          (println "Subfield is" subfield)
-          (println "Subfield maps" value-maps))))
+  ;; Merge the two maps without their values
+  (let [merged-map (merge-with
+                     (fn [existing-values new-values]
+                       ;; Find the values in common by using map-b and then merge those maps.
+                       ;; The merge-with here recursively calls into the same function
+                       (->> (merge-with merge-hierarchical-maps
+                                        (map-by :value existing-values)
+                                        (map-by :value new-values))
+                            vals
+                            vec))
+                     (dissoc hm1 :value :uuid)
+                     (dissoc hm2 :value :uuid))]
+    ;; Add value back in if it was there originally
+    (if (contains? hm1 :value)
+      (assoc merged-map :value (:value hm1))
+      merged-map)))
 
 (comment
 
-(def example-keywords
-  [{:a "A1" :c "C1" :uuid "a1c1"}
-   {:a "A1" :c "C1" :d "D1" :uuid "a1c1d1"}
-   {:a "A2" :uuid "a2"}
-   {:a "A2" :d "D1" :uuid "a2d1"}
-   {:a "A3" :b "B1" :c "C1" :d "D1" :uuid "a3b1c1d1"}
-   {:a "A3" :c "C2" :uuid "a3c2"}
-   {:a "A3" :d "D2" :uuid "a3d2"}])
+  (def example-keywords
+    [{:a "A1" :c "C1" :uuid "a1c1"}
+     {:a "A1" :c "C1" :d "D1" :uuid "a1c1d1"}
+     {:a "A2" :uuid "a2"}
+     {:a "A2" :d "D1" :uuid "a2d1"}
+     {:a "A3" :b "B1" :c "C1" :d "D1" :uuid "a3b1c1d1"}
+     {:a "A3" :c "C2" :uuid "a3c2"}
+     {:a "A3" :d "D2" :uuid "a3d2"}])
 
   (def hm1
     (keyword->hierarchy (first example-keywords) [:a :b :c :d]))

    (keyword->hierarchy (nth example-keywords 2) [:a :b :c :d]))



  (merge-hierarchical-maps hm1 hm2)
  )

(defn create-branch-nodes

        (let [cmr-keyword-scheme (translate-keyword-scheme-to-cmr orig-keyword-scheme)
              gcmd-keyword-scheme (translate-keyword-scheme-to-gcmd orig-keyword-scheme)
              keywords (vals (gcmd-keyword-scheme (kf/get-gcmd-keywords-map context)))
              hierarchical-keywords (parse-hierarchical-keywords
                                      (cmr-keyword-scheme frf/nested-fields-mappings) keywords)]
          {:staus 200
