replace loop with a macro