bug fix in multithreading