refactor macros to library