Fix incorrect looping limits.
One cannot iterate across an entire list if one both removes an entry
and increments the index into the list. Do one or the other or you
will end up with bugs like 11556768 which is now fixed.
Change-Id: I57f1ad13075a005cae3c1cbfae10e230d9af143a