shutdown the agent correctly