added optional error reporting