added smoothing function