port to python 3 and some cleanups