Added code to check for NaNs in singular matrix