use amean function instead of manual calculation