         boxes))))
 
 
+(defn stop-boxes
+  "Calls the stop function of all boxes in the specefied boxes map."
+  [boxes]
+  (doseq [[name box] boxes]
+    (try
+      ;; Box stop logic here.
+      (catch Throwable ex
+        (println "Exception while stopping module" name ":" ex)
+        ;; Kill box here?
+        ))))
+
+
+;;; Command loop.
+
 (defmulti handle-command
-  "May return a pair, where the first item is an updated state, and
-  the second item is an updated boxes. If no value is returned, or a
-  value in the pair is nil, then the state and/or boxes are not
-  updated in the command loop."
+  "This multi-method dispatches on the command (the first word in the
+  command string). It receives the arguments, the spec, the current
+  command-loop state and the running boxes map. This method may return
+  a pair, where the first item is an updated state map, and the second
+  item is an updated boxes map. If no value is returned, or a value in
+  the pair is nil, then the state and/or boxes are not updated in the
+  command-loop."
   (fn [command args spec state boxes] command))
 
 



(defn handle-commands
  [spec systems boxes]
  ;; Handle commands like starting and stopping modules, and stopping the application.
  ;; This can be done through typing here, updates on the file system, through sockets...



(defn start-boxes
  "Starts all the boxes in the specified spec."
  [spec systems]
  (let [{:keys [config modules resolve-dependencies]} spec]
    (loop [modules modules
