Vastly improved the efficiency of time series calculation