adding onClose event