convert global variables to functions