Fixes a bug related to multithreading