Port this to python 3.x.