Added a check for division by zero.