check and prevent div by zero