Fix multithreading bug

Revert part of commit 090f557 that caused a multithreading bug.