remove duplicates function - works depending on char set