Python 3 compatibility

I've made several changes for python 3 compatibility. Running tox for these environments no longer reports failures.