adapted to python 3