added NaN check in residual, added verbose array debugging