Another BIG refactoring in progress in the agent