bug fix for multithreading