Fix Python 3 incompatibility issues