sort and remove duplicates