Add onClose function.