Multithreading fix: localize unneeded global variable