Put some part of those macros back into a function

As functions are more easily reasoned about than macros, and I could
turn some of the new macros I made back into a function.