Compat

Lots of stupid changes to get python3 to work. Mostly around unicode/byte strings :(