ported to python3 (by 2to3)