update function for normal use - remove testing bit
collect the average and stdev calculations into two variables to avoid having to calculate them every time. Extend error checking