calculate average implemented