Add support for clean shutdown