Added check for case when denominator equals zero.