Change global variables to functions.