Wrote the algorithm