fix bug in merge_duplicates