Fixing portability problems between Python 2 and 3