Fixed several problems with nan values being passed