Factor out common elements of ID generation