Rework loop to be less confusing. Coverty 519 made me read this code, but this isn't the 'bug' it found.