Add null check in ID generator