Making a more polished verrsion fo the .doAverage() function