advanceState is advancing the state from the previous state so several loops may have problems. I would look at using channel ports suite instead.
Setting the rects to 0,0,0,0 should reset advanceState but that is an 'as is' warranty statement if you know what i mean.