Fixed a close bug in the event handling