Add clean shutdown code