This conditional was treating the start and end of the frame interval inversely. Fix that by changing the condition and also initialize i at 0 for symmetry with other similar checks in the file.