Clean up error handling code and add additional checks for macro definition and usage.