Improvements to multithreading loop