Cleanup: Removing unused variables.
Cleanup: Refactoring XML output code to facilitate introduction of protocol xml output.