add error reporting code