fixed error in averageMedian function