More refactoring.

More refactoring of Agent.java, lots more to do though.