Python 3 fixes

Problems identified in 0125773e610e2cf39935384fe30eab69df311d27. Should all be fixed and 2to3 should no longer be required.