Fix dangerous iterator use.