Updated to delete all duplicates instead of just the first one