Added comments for residuals function.