Tried to improve smoothing algorithm - unfinished!