Moving unique generation to function