Minor logic fix to nested loop counters.