Fix prune_duplicates sorting bug