Doing a better job of de-referencing variables in the residuals function.