Some refactoring in preperation for macros