Converting global variables to local