Added smoothing, and optimized some of the code.