Python 3 and PyPy fixes and some other minor cleanups