fixed bug with multithreading