 ;; -----------------------------------------------------------------------------
 
 (defn init [data ajax-chan]
-  (go-loop []
-    (let [response (<! ajax-chan)]
-      (when (and (= (:current-state @data) :loading)
-                 (= (:current-search @data) 
-                    (:search-term response)))
-      (cond
-        ; error
-        (:error response)
-        (om/transact! data
-          #(assoc % :current-state :error
-                    :error (:error response)))
-        ; empty response
-        (empty? (:items response))
-        (if (empty? (:current-items @data))
+  (go (loop []
+      (let [response (<! ajax-chan)]
+      (when 
+        (and (= (:current-state @data) :loading)
+             (= (:current-search @data) 
+                (:search-term response)))
+        (cond
+          ; error
+          (:error response)
           (om/transact! data
             #(assoc % :current-state :error
-                      :error :empty-search))
-          (om/transact! data 
-            #(assoc % :current-state :loaded-final)))
-        :else
-        (om/transact! data
-          #(assoc % :current-state :loaded
-                    :current-items (concat (:current-items @data) 
-                                           (:items response))
-                    :before (:timestamp (last (response :items)))))))
-      (recur))))
+                      :error (:error response)))
+          ; empty response
+          (empty? (:items response))
+          (if (empty? (:current-items @data))
+            (om/transact! data
+              #(assoc % :current-state :error
+                        :error :empty-search))
+            (om/transact! data 
+              #(assoc % :current-state :loaded-final)))
+          :else
+          (om/transact! data
+            #(assoc % :current-state :loaded
+                      :current-items (concat (:current-items @data) 
+                                            (:items response))
+                      :before (:timestamp (last (response :items)))))))
+      (recur)))))

        ch  (chan)]
    (.send req nil #(put! ch %))
    (go (let [[v c] (alts! [t ch])]
          (case
            ; timeout
            (= c t)
            (>! ajax-chan {:error :timeout})

            (not (= (.. v -meta -status) 200))
            (>! ajax-chan {:error :ajax})
            ; response OK
            :else
            (let [items (-> (.. v -response)
                            (js->clj :keywordize-keys true)
                            (#(filter (fn [item] (= (:type item) "photo")))))]
              (>! ajax-chan {:error false
                             :search-term search-term
                             :items items})))))))
