agent: Lots of work
Refactor some code that is responsible for fork(), etc