replace duplicates with macros