Avoid division by zero when calculating mean