Wrote the algorithm without threads..