Multithreaded Code separated from the original file

Now its easier to understand the parallel code as it is separated from
the main function.