         (condp = event-v
 
               ;; Setup the flow coordinator:
-              ;;  1. Initialise the state  (seen-events and started-tasks)
-              ;;  2. dispatch the first event, to kick start
-              ;;  3. arrange for the events to get forwarded to this handler
+              ;;   1. Initialise the state  (seen-events and started-tasks)
+              ;;   2. dispatch the first event, to kick start
+              ;;   3. arrange for the events to get forwarded to this handler
               :setup {:db (set-state db #{} #{})
                       :dispatch first-dispatch
-                      :event-forwarder {:register id
-                                        :events   all-events
-                                        :to       [id ]}}
+                      :event-forwarder {:register    id
+                                        :events      (apply set/union (map :events rules))
+                                        :dispatch-to [id]}}
 
               ;; Teardown the flow coordinator:
-              ;;  1. remove this event handler
-              ;;  2. remove state
-              ;;  3. stop the events forwarder
+              ;;   1. remove this event handler
+              ;;   2. remove any state stored in app-db
+              ;;   3. stop the events forwarder
               :halt {:db (dissoc db db-path)
                      :event-forwarder {:unregister id}
-                     :deregister-event-handler id})          ;; XXX write this effects handler
+                     :deregister-event-handler id})
 
               ;; A new event has been forwarded to this handler. What does it mean?
               ;;  1. does this new event mean we need to dispatch another

                      (fn [db] (get-in db db-path))
                      (fn [_]  @local-store))

        rules  (massage-rules id rules)
        all-events  (apply set/union (map :events rules))]       ;; all of the events refered to in the rules

    ;; return an event handler which will manage the flow
    ;; This event handler will receive 3 kinds of events

                {:db       (set-state db new-seen-events new-started-tasks)
                 :dispatch (concat (map :dispatch ready-tasks))}))))


(re-frame.core/def-fx
  :aync-flow
  (fn [{:as flow :keys [id]}]
    (re-frame.core/def-event-fx
      (or id default-id)                                 ;; add debug middleware???  XXX
      (make-flow-event-handler flow))
    (re-frame.core/dispatch [id :steup])))

