Fixing deduplication routine