Added residual external function.