Fix closing event on error