Refactor smoothing func