documented the algorithm a bit