Changed calcResidual