Added error event handling.