Added residual functions