This whole for loop comes across as hard to follow, and I think you may have mistakenly added a level of complexity to it.