Modified code and fixed pearson average.