updated to use the average