listen to the close event