Improve smoothing algorithm

- add checks for index out of bounds
- smoothing factor now calculated so that it begins and ends at correct factors
    - that is, it won't begin/end at a factor that is greater/lower than the starting factor