some restructuring to be more PEP-8-ish
simplify the logic for the smoothing