Bug fix

Found a bug where I free the agent too early. The problem is resolved
with this commit