Improving summary statistics function