refactor code for sequence