Added check for division by zero.