Fix average calculation