Adding function to average values