Port to python3

These changes seems to make the code compile and work with python3.