a couple fixes to make the agent more robust