Changes code to use  global instead