REF/BUG: more py3 compat, fix missing variables (globals temporarily)