Conversion to python 3, mostly