Added safety check when removing dialog