move global variables into function