port to python 3 (not finished)