refactor macro-related code