Fixed a bug in unique id assignment