                  (conj (pop chunks) l))
                (conj chunks achunk))
              (vector achunk)))))
+
+(defn- finish-bin-index
+  [bin-index]
+  (->> bin-index
+       (seq)
+       (sort-by first)
+       (map (partial zipmap [:bin :chunks]))))
 
 (defn- init-linear-index []
   {:index (gen-vec max-lidx-size 0)

            ;; # of bins
            (lsb/write-int wtr (inc n-bin))
            (doseq [bin (:bins index)]
              (write-bin wtr (first bin) (second bin)))
            ;; meta data
            (write-meta-data wtr (:meta index))))
        ;; linear index

                                  no-coordinate-alns)
            indices' (if new-ref?
                       (assoc indices ref-name {:meta (:meta-data idx-status)
                                                :bins (finish-bin-index (:bin-index idx-status))
                                                :lidx (optimize-lidx (:index (:linear-index idx-status))
                                                                     (:largest-seen (:linear-index idx-status)))})
                       indices)]
        (recur rest ref-name' idx-status' no-coordinate-alns' indices'))
      (assoc indices ref-name {:meta (:meta-data idx-status)
                               :bins (finish-bin-index (:bin-index idx-status))
                               :lidx (optimize-lidx (:index (:linear-index idx-status))
                                                    (:largest-seen (:linear-index idx-status)))}
                     :no-coordinate-alns no-coordinate-alns))))
