                        buf-or-n)
                      ch-id))))
 
+(defn chan-ago-world [ch]
+  (when (instance? WrapManyToManyChannel ch)
+    (.-ago-world ch)))
+
 (defn chan-seqv [ch]
   (when (instance? WrapManyToManyChannel ch)
     (.-seqv ch)))
 
-(defn chan-ago-world [ch]
+(defn chan-buf-id [ch]
   (when (instance? WrapManyToManyChannel ch)
-    (.-ago-world ch)))
+    (.-buf-id ch)))
 
 ; --------------------------------------------------------
 
 (defn ago-reg-state-machine [ago-world state-machine-arr buf-id]
-  (swap! ago-world #(seqv+ (assoc-in % [:smas-new buf-id] state-machine-arr))))
+  (swap! ago-world #(-> %
+                        (assoc-in [:smas-new buf-id] state-machine-arr)
+                        (dissoc-in [:smas buf-id])
+                        (seqv+))))
 
 (defn ago-run-state-machine [ago-world state-machine-arr buf-id]
   (swap! ago-world #(-> %

    (commit [_] (when (active-cb) f))))

(defn ssa-take [state blk ^not-native c]
  (let [active? #(seqv-alive? (chan-ago-world c) (chan-seqv c))]
    (if-let [cb (protocols/take!
                 c (fn-handler
                    active?
                    (fn [x]
                      (when (active?)
                        (ioc-macros/aset-all! state ioc-helpers/VALUE-IDX
                                              x ioc-helpers/STATE-IDX blk)
                        (ioc-helpers/run-state-machine-wrapped state)))))]
      (do (ioc-macros/aset-all! state ioc-helpers/VALUE-IDX
                                @cb ioc-helpers/STATE-IDX blk)
          :recur)
      nil)))

(defn ssa-put [state blk ^not-native c val]
  (let [active? #(seqv-alive? (chan-ago-world c) (chan-seqv c))]
    (if-let [cb (protocols/put!
                 c val (fn-handler
                        active?
                        (fn [ret-val]
                          (when (active?)
                            (ioc-macros/aset-all! state ioc-helpers/VALUE-IDX
                                                  ret-val ioc-helpers/STATE-IDX blk)
                            (ioc-helpers/run-state-machine-wrapped state)))))]
      (do (ioc-macros/aset-all! state ioc-helpers/VALUE-IDX
                                @cb ioc-helpers/STATE-IDX blk)
          :recur)

            [cljs.core.async.impl.protocols :as protocols]))

(defn acopy [asrc adst & start-idx]
  (loop [idx (or (first start-idx) 0)]
    (when (< idx (alength asrc))
      (aset adst idx (aget asrc idx))
      (recur (inc idx))))
