added derivative and better smoothing