Switch to using an iterator to avoid raw types / unchecked conversion warnings.