move global var out of callback function