This code will create a set from a multiset (remove duplicates).
I didn't do all that much, most code is from the original.