Add proper shutdown machinery