Adding the smoothing code