More sophisticated detection, and do not return NaN.  More test data.