Ported to python 3.