fixed calculation of mean