Corrections based on feedback from Chris. Significantly, I modified the algorithm and added a step by step example for clarity.