Graceful shutdown improvements