Added buggy code for multithreading.
Unfortunately, as soon as you run the multithreaded bit, it stops working, so I've commented it out.