Main body of work on the alg done