Working in Python 3 after some adjustment to globals usage