Fix many warnings on Python 3

Many more remain.