fixed bug and split up functions for smoothing