Replace some global variables with functions