improved error checking macro