Improving the code of rollingStats