Changing python code to support python 3

Fixes #139, hopefully.