Deduplication logic