add a safeguard against rare NaNs