Added support for safe exit.