Oh, I see what's happening: you're reusing this as the index below. Maybe just use an new variable?