Fixed error when saving multiple time series
Some refactoring.