Ported for python3.