Some code simplification and attempt at Py3k fix.
Use text mode.
Automatic Py3k merge for testing