fix issue with global variables used by thread