ported code to python2