Fixed a bug where dialog was not properly removed when closed through the 'X' button