Rewrote the logic behind threads.