 
 (defn- ->service-mode
   [service-spec]
-  (str/lower-case (name (first (keys (:Mode service-spec))))))
+  (when service-spec
+    (str/lower-case (name (first (keys (:Mode service-spec)))))))
 
 (defn ->task-node
   [node-id nodes]

      :state (get-in task [:Status :State])
      :status {:error (get-in task [:Status :Err])}
      :desiredState (:DesiredState task)
      :serviceName service-name
      :nodeName (or node-name node-id))))

(defn ->tasks

(defn ->task-service
  [service-id services]
  (first (filter #(= (:ID %) service-id) services)))

(defn ->task-name
  "If there is no matching service for task use task-id as name. Otherwise follow rules"
  [task-id node-id slot service-name service-mode]
  (cond
    (= "replicated" service-mode) (str service-name "." slot)
    (= "global" service-mode) (str service-name "." node-id)
    :else task-id))

(defn ->task
  [task nodes services]
