Handle "divide on zero" exception.

Calculations are done as suggested by Clint.