adatped to Python 3