       (cond (>= i (count table))
             (compressed-table table equiv)
             
-            (or (>= j (count gens)) (not= i (pfind equiv i)))
+            (or (>= j (count gens)) (not= i (equiv i)))
             (recur table equiv (inc i) 0)
             
             ((table i) (get gens j))

         equiv equiv]
    (if-let [[i j] (first q)]
      (let [q (pop q)
            a (pfind equiv i)
            b (pfind equiv j)]
        (if (= a b)
          (recur q table equiv)
          (let [equiv (punion equiv a b)
                [table q] (merge-rows table equiv q a b)]
            (recur q table equiv))))
      [table equiv])))

        row-a (merge (table a) (table b))
        row-b (merge (table b) (table a))
        q (into q (for [g (keys row-a)
                        :when (not= (equiv (row-a g)) (equiv (row-b g)))]
                    [(row-a g) (row-b g)]))
        table (conj table [a row-a] [b row-a])]
    [table q]))
