Updated the closing event to function properly