Added comments for each section of the algorithm