added the err term for residual error