Added smoothing function