improve macro. fix some bugs