fixed the for loop in function mean