modified to make some of the macros work better with templates