Making dedup.sh more robust