fixing averaging calculation