Added error reporting code