modified the macro and some logic