Fixed issue, if PNG is not on last iteration.

Previous commit added a bug, where if PNG was not on the last iteration, index would be set to 0.