         g (-> graph
               (update-in [:layers p-layer-id :nodes] conj p-node)
               (update-in [:layers q-layer-id :nodes] conj q-node)
-              (update-in [:p] conj p-node)
-              (update-in [:q] conj q-node)
+              (update-in [:ps] conj p-node)
+              (update-in [:qs] conj q-node)
               (add-edge last-node p-node characters)
               (add-edge p-node q-node characters))]
     [g q-node]))

  "Step 1 of ESK - replace all p nodes with edges and merge segment containers"
  [graph layer]
  (->> (:ordered layer)
       (map #(if (contains? (:p graph) %)
               ;; p nodes always have only one successor
               [(-> (:succs graph) (get %) first)]
               %))

(defn- set-qs-non-qs
  "ESK requires a layer's nodes to be split into lists of q-nodes and non-q-nodes"
  [graph layer]
  (->> ((juxt filter remove) #(contains? (:qs graph) %) (:nodes layer))
       (map set)
       (interleave [:qs :non-qs])
       (apply (partial assoc layer))))
