Function to error logging for protocol. Implemented some protocol function for agents.
Added some error handling to Protocol, and cleaned it up a bit.