Added duplicate detection.