Fix Python 3 compatibility and missing globals

Would you mind cutting a release after pulling this? Thanks!