   (def node-type
     (s/OR branch-node-type leaf-node-type))
 
-(def expected-result
+  (def expected-result
+    {:a [{:value "A1"
+          :subfields ["c"]
+          :c [{:value "C1"
+               :uuid "a1c1"
+               :subfields ["d"]
+               :d [{:value "D1"
+                    :uuid "a1c1d1"}]}]}
+         {:value "A2"
+          :uuid "a2"
+          :subfields ["d"]
+          :d [{:value "D1"
+               :uuid "a2d1"}]}
+         {:value "A3"
+          :subfields ["b" "c" "d"]
+          :b [{:value "B1"
+               :subfields ["c"]
+               :c [{:value "C1"
+                    :subfields ["d"]
+                    :d [{:value "D1"
+                         :uuid "a3b1c1d1"}]}]}]
+          :c [{:value "C2"
+               :uuid "a3c2"}]
+          :d [{:value "D2"
+               :uuid "a3d2"}]}]})
+
+  {:a "A1" :c "C1" :uuid "a1c1"}
+
   {:a [{:value "A1"
-        :subfields ["c"]
-        :c [{:value "C1"
-             :uuid "a1c1"
-             :subfields ["d"]
-             :d [{:value "D1"
-                  :uuid "a1c1d1"}]}]}
-       {:value "A2"
-        :uuid "a2"
-        :subfields ["d"]
-        :d [{:value "D1"
-             :uuid "a2d1"}]}
-       {:value "A3"
-        :subfields ["b" "c" "d"]
-        :b [{:value "B1"
+        :subfields ["b"]
+        :b [{:value nil
              :subfields ["c"]
              :c [{:value "C1"
-                  :subfields ["d"]
-                  :d [{:value "D1"
-                       :uuid "a3b1c1d1"}]}]}]
-        :c [{:value "C2"
-             :uuid "a3c2"}]
-        :d [{:value "D2"
-             :uuid "a3d2"}]}]})
-
-{:a "A1" :c "C1" :uuid "a1c1"}
-
-{:a [{:value "A1"
-      :subfields ["b"]
-      :b [{:value nil
-           :subfields ["c"]
-           :c [{:value "C1"
-                :uuid "a1c1"}]}]}]}
-
-(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"}])
+                  :uuid "a1c1"}]}]}]}
+
+  (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 keyword-hierarchy-example [:a :b :c :d])
 
-  (create-branch-nodes :a [:b :c :d] example-keywords )
-
-  {:b [{:value value
-        }]
-   :c [{:value ...}]}
-
-  (keyword->hierarchy (first example-keywords) [:a :b :c :d])
+  (def expected-merged
+    {:a [{:value "A3"
+          :b [{:value nil
+               :c [{:value nil
+                    :d [{:value "D2"
+                         :uuid "a3d2"
+                         }]}
+                   {:value "C2"
+                    :uuid "a3c2"
+                    :d [{:value nil}]
+                    }]}
+              {:value "B1"
+               :c [{:value "C1"
+                    :d [{:value "D1"
+                         :uuid "a3b1c1d1"
+                         }]}
+                   ]}]}
+         {:value "A2"
+          ; :uuid "a2"
+          :b [{:value nil
+               :c [{:value nil
+                    :d [{:value "D1"
+                         :uuid "a2d1"
+                         }
+                        {:value nil}]}]}]}
+         {:value "A1"
+          :b [{:value nil
+               :c [{:value "C1"
+                    :uuid "a1c1"
+                    :d [{:value "D1"
+                         :uuid "a1c1d1"
+                         }
+                        {:value nil}]}]}]}]})
+
+
+  (->> example-keywords
+       (map #(keyword->hierarchy % [:a :b :c :d]))
+       (reduce merge-hierarchical-maps)
+       (= expected-merged)
+       )
+
+  (map #(keyword->hierarchy % [:a :b :c :d]) example-keywords)
+
   )
 
 ;; Three steps

        (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)))
              _ (cmr.common.dev.capture-reveal/capture keywords)
              hierarchical-keywords (parse-hierarchical-keywords
                                      (cmr-keyword-scheme frf/nested-fields-mappings) keywords)]
          {:staus 200


(defn merge-hierarchical-maps
  [hm1 hm2]
  ;; 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 hm1
    (keyword->hierarchy (first example-keywords) [:a :b :c :d]))
