Python 3 port

Building on @burnpanck's work in PR #106 with a few fixes. I have done a reasonable review pass over @burnpanck's work. Can someone review my modifications at the end?