First pass at py3 compatibility

Ran 2to3 and collected all necessary changes. Addressed most
of them using the six module