Fix reference, port and pid encoding problem in python 3.  Minimize use of unicode strings when possible.