use global variable correctly