Fix a bug in duplicates checking