completed the inverse r-squared algorithm