alter shutdown procedure so that stoping the agent is the last possible thing to happen