Added checks to prevent divide by zero errors.