Avoided some problems when modal components are left open during shutdown.