Change code back to Python 2. Fixed all shadow variables in scope.