Fixed bug in duplicate detection