Made some porting to python 3.x