added a smoothing function