Minor speed improvement: only compute uniqueId (at most) once.