If you want it not to stop, you have to reset index to some value. Find the matching }, and add an else clause in which you set index to 0.
I don't think that will work due to the way that index is calculated based on the elapsed time that the program has been running.