added Protocol.debug and made some code cleanup.
code cleanup and added GPL licence to some of the files.