Add basic support for modal windows handling.
Fix crash on dialog close