Updated again for multithreading.