Added error handling routines and macros