Fix python 3 compatibility

Still requires significantly better test coverage.
Resolves #78