protect mean calculation against divide by zero