group global variable and reformat code