Robust TUI exit