py3 compatability

Some pretty minor changes needed to get this to play nice with python3.

Still seems to work under 2.7.8 for me with the changes as well.