Fix divide by zero problem.
Handle nan case.