fix bug in average correction function