commented the algorithm