minor rewrite for Python 3 support. Some other fixes in corresponding files.
Merge pull request #8 from eill/master

Python 3 support.