update the weight algirithm