Added encode for Python 3 compatability.