Various python3 fixes.

Still need to make more before this runs smoothly in Python 3.