classes and methods for residuals