made changes to the macro
somewhat more functional