Fixed the ensure unique id function. Yet algorithm needs improvement