Refactoring of modal dialog code.