Better closing of the dialog