Clean up some code around setting the agent
Merge pull request #1197 from FredKSchott/get-new-agent

Clean up some code around setting the agent