refactored smoothing code