Added support for clean shutdown