fix average calculation