Refactoring of the data structures in agent, similar to what was done in proxy.