to_unicode changes to avoid crashing python3