Implemented a smoothing function