   (let [parent-team-map (->> (get-in node [:data :teams])
                              (map #((juxt :name identity) %))
                              (into {}))]
-    (if (and (get node :upper) (get node :lower))
+    (if (branch? node)
       (-> (update-in node [:upper] (partial update-child-expected-value parent-team-map))
           (update-in [:lower] (partial update-child-expected-value parent-team-map)))
       node)))

  "Update the expected value of each team in the field using parent-team-map.  The expected value for each team in the
  field is the team's average points plus the expected value of the team in the parent-team-map."
  [parent-team-map node]
  (if (seq (get-in node [:data :teams]))
    (update-in
      node
      [:data :teams]
      (partial
        map
        #(update-in % [:expected-value] (fnil + 0 0)
                    (get-in parent-team-map [(:name %) :expected-value])
                    (:avg-pts %))))
    node))

(defn- update-expected-value
  "For each child in children, update the expected value of the teams in that child's field.  The expected value for each team

    treeify
    bracket))

(defn- branch? [node]
  (and (map? node) (contains? node :upper) (contains? node :lower)))

(defn children [node]
  ((juxt :upper :lower) node))

(defn make-node [existing [upper lower]]
  (-> (assoc-in existing [:upper] upper)
      (assoc-in [:lower] lower)))

(defn- update-round [rnd node]
  (assoc-in node [:data :round] rnd))

(defn- compute-round [loc]
  (if (zip/end? loc)
    loc
    (if-let [parent-round (some-> (zip/up loc)
                                  zip/node
                                  (get-in [:data :round]))]
      (recur (zip/next (zip/edit loc (partial update-round (dec parent-round)))))
      (recur (zip/next loc)))))

(defn round-info [max-rounds tree]
  (->> (update-round max-rounds tree)
       (zip/zipper
         branch?
         children
         make-node)
       compute-round
       zip/root))

(defn weighted-pairing-log5
  "Compute and update the chance that Team a and Team b will advance when playing against each other,
