Fixed bug with multithreading