Fix a bunch of incompatibilities with python3.x