Turned macros into functions where possible