fix the looping between sequences