Added Threads to algorithm