fixing up the smoothing algorithm