Remove duplicates using hash method