Make Python 3 compatible, pass 1

All tests pass on Python 2.6 and Python 3.4, but since test coverage is
only ~22%, I may have missed some things.