                          t2 (:tuples rel)]
                      (let [res (aclone t1)]
                        (dotimes [i len]
-                         (when-let [idx (prop->index (aget copy-map i))]
+                         (when-let [idx (aget copy-map i)]
                            (aset res i (nth t2 idx))))
                        res))
                    (next rels)

(defn lookup-pattern-db [db pattern callback]
  ;; TODO optimize with bound attrs min/max values here
  (let [search-pattern (mapv #(if (symbol? %) nil %) pattern)
        attr->prop     (->> (map vector pattern ["e" "a" "v"])
                            (filter (fn [[s _]] (free-var? s)))
                            (into {}))]
    (dc/-search db search-pattern (fn [datoms] (callback (Relation. attr->prop datoms))))))

(defn matches-pattern? [pattern tuple]
  (loop [tuple   tuple


;;

(defn tuple-key-fn [idxs]
  (if (== (count idxs) 1)
    (let [idx (first idxs)]
