adding onClose method