Fixing some shutdown code.