Python 3 compatibility fixes

- mostly low-hanging syntax changes
- some reworking of string handling in general