better implementation of gather_seqs

more efficient and easier to understand