More bug fixes discovered through Python 3 testing.

Also improved unicode handling and testing.
PEP-8 fix for previous commit.