Improved shutdown hook