Fix a crash on shutdown due to destruction order.
Fix Dialogs not closing after clicking X.
Migrate EntityChooser and a lot of helper code.