added error event handling