Fix some Python 3 incompatibilities