Closing dialogs refinement. Fixes #573