Added check for NaN when dividing

Ran across an issue that caused the library to crash due to dividing by 0