added a flag to control the time series length