Figure 2. Algorithm used, explanations.