Porting code to Python 3