Miscellaneous Python 3 fixes