changed order of mean and sd calculations to avoid sd being included in mean