replace macros with functions