Protocol cleanup

Some changes to udoprog's protocol.py cleanup plus unit tests