Added error handler events, and improved the way it handles them.