Improved trendline function.