Get closer to supporting Python 3

I wasn't successful in getting everything to work with Python 3 (yet!) but I fixed a lot of issues. The code should still work with Python 2