optimized average calculation