Sort and remove duplicates