Improved code for timeseries()