Added encode for Python 3 compatibility.