eliminate some duplicate code in dict_merge