Update code for python3 compatibility.