Fix for multithreading problems