Improve unicode handling for python 3 compatibility.