fixed multithreaded issues