added weighted residual error in ResidualCost