factor out safe-restart