improve remove duplicates solution