most of the code converted to macros