Factorized code for dialogs.