Bug fix: out-of-range indices in residuals()