added residual diagnostics