modified updating formula to run faster