Some code simplification and attempt at Py3k fix.
Use text mode.