Ripped AgentOpcode source for cleanup

Inserted AgentOpcode source code to make it ready for public use and
tried to abstract more of the code.