Can you either document the steps of this algorithm with inline comments or else provide a reference in the form of a link to a place where this algorithm is explained?