Python3 compatibility

Including fixes for py3 unicode string and bytes separation.
Tested with both py 2 and 3.