added some clarity to the algorithm