More general smoothing function