Added enhanced memory deallocation.
Corrected agent formatting and debugging.