Added checking of duplicated ids