Refactor next_seq