Fixing average calculation