                (start! [this config]
                  (reset! run true)
                  (reset! video-source (if (:video-sim config)
-                                        (do (println "Using simulated video") (InetAddress/getByName nil))
-                                        (do (println "Real video") comm/drone-ip)))
-                 (task/submit :video video-streaming)
+                                        (InetAddress/getByName nil)
+                                        comm/drone-ip))
+                 (task/submit :video video-streaming-task)
                  config)
                (stop! [this]
                  (reset! run false)

  target)

(defn read-fully [^InputStream in ^bytes buffer ^long offset ^long size]
  (IOUtils/readFully in buffer offset size))

(defn make-reader [^InputStream in]
  (fn []

    (.setSoTimeout 2000)
    (.connect (InetSocketAddress. ^InetAddress @video-source 5555))))

(def run (atom false))

(defn send-init-video [^Socket socket]
  (doto (.getOutputStream socket)
    (.write (byte-array (map bin/ubyte [1 0 0 0])))
    (.flush)))

(defn video-streaming-task []
  (try
    (while @run
      (let [socket      (open-socket)
            reader      (make-reader (-> socket .getInputStream BufferedInputStream.))
            decoder     (make-decoder)]
        (try
          (send-init-video socket)
          (while @run
            (->> (reader) (decoder) (swap! world assoc :image)))
          (catch java.io.IOException e
            (println "I/O error:" e ": reconnecting...")
            (Thread/sleep 1000))
          (finally
            (try (.close socket) (catch Exception _))))))
    (catch Throwable e
      (println "exception while processing video stream" e)
      (.printStackTrace e))))
