These 3 blocks are very repetitious.  You should DRY this out and deal with the sequence index without needing to repeat the same code 3 times.