some work on Python 3 compatibility (still not quite working)