fixed access to variables for multithreading