Speed improvement in foreach/repeat

Don't generate too many UUIDs.