Fixed error with multithreading