Replace some common code with a macro.