Massive refactoring, agent is now a smart guy.