      (fn [[ungrouped grouped]]
        [column-id
         (reduce into []
-                (into
+                (concat
                  (interleave ungrouped grouped)
                  (drop (count grouped) ungrouped)))])
      (cartesian-product [ungrouped-slices grouped-permutations]))))
 
 (defn layout-permuations
-  [layout]
-  (let [groups (get-card-deps)
-        columns-permutations (map (partial column-permutations groups) layout)]
-    (map
-     (partial into {})
-     (cartesian-product columns-permutations))))
+  [layout card-deps]
+  (->> (map (partial column-permutations card-deps) layout)
+       cartesian-product
+       (map (partial into {}))))
 
 (defn optimize-layout
-  [layout]
-  (let [permutations (layout-permuations layout)]
+  [layout card-deps]
+  (let [permutations (layout-permuations layout card-deps)]
     (transduce
-     (map (fn [layout] [(get-layout-score layout) layout]))
+     (map (fn [layout] [(get-layout-score layout card-deps) layout]))
      (fn
        ([final]
           (second final))
        ([best current]
           (if best
             (let [[best-score _] best
-                  [current-score _] current]
+                  [current-score l] current]
               (if (better-score current-score best-score)
                 current
                 best))


(defn handle-layout-change
  [layout]
  (-> (optimize-layout layout)
      apply-layout))

(defn listen-drag

           (.addDragList drag-group list goog.fx.DragListDirection/DOWN))
    (doseq [card (get-cards)] (add-card card))
    (.init drag-group)
    (listen-drag drag-group (get-cards-layout))))
