Approximation Error To High in CKKS

I have working code for my project. Now I’m trying to change the architecture to multiparty scenario where I define on high level the number of parties.
Therefore, I took the code from src/pke/examples/tckks-interactive-mp-bootstrapping-Chebyshev.cpp and changed it in a way that the number of parties is flexible.
For some calculations it does work as expected, but especially for more complex calculations I’m getting an “approximation error too high”
Woud you please double-check my code?

std::cout << "Key generation for " << numparties << " parties started." << std::endl;
            numParties = numparties;
            for (int i = 0; i < numparties; i++) {
                Party party;
       = i;
                if (0 == i)
                    party.kpShard = cryptoContext->KeyGen();
                    party.kpShard = cryptoContext->MultipartyKeyGen(parties[i-1].kpShard.publicKey);
            std::cout << "Joint public key for (s_0 + s_1 + ... + s_n) is generated..." << std::endl;

            // Assert everything is good
            for (int i = 0; i < numparties; i++) {
                if (!parties[i].kpShard.good()) {
                    std::cout << "Key generation failed for party " << i << "!" << std::endl;

            // Perform Key Generation Operation

            // Generate evalmult key part
            std::cout << "EvalMultKey generation started." << std::endl;            

            std::vector<EvalKey<DCRTPoly>> EvalMultKeyTemp;
            EvalKey<DCRTPoly> evalMultKeyFinal;
            for(int i = 0; i<numparties; i++)
                    EvalMultKeyTemp.push_back(cryptoContext->KeySwitchGen(parties[i].kpShard.secretKey, parties[i].kpShard.secretKey));
                    auto EvalMultKeyi = cryptoContext->MultiKeySwitchGen(parties[i].kpShard.secretKey, parties[i].kpShard.secretKey, EvalMultKeyTemp[0]);

                    EvalMultKeyTemp.push_back(cryptoContext->MultiAddEvalKeys(EvalMultKeyTemp[i-1], EvalMultKeyi, parties[i].kpShard.publicKey->GetKeyTag()));

                    std::vector<EvalKey<DCRTPoly>> EvalMultKeyAdd;
                    for(int j=0; j< numparties; j++){
                        EvalMultKeyAdd.push_back(cryptoContext->MultiMultEvalKey(parties[j].kpShard.secretKey, EvalMultKeyTemp[i], parties[i].kpShard.publicKey->GetKeyTag()));

                    evalMultKeyFinal = cryptoContext->MultiAddEvalMultKeys(EvalMultKeyAdd[0], EvalMultKeyAdd[1], EvalMultKeyAdd[0]->GetKeyTag()); 
                    for(int j=2; j<numparties; j++){
                        evalMultKeyFinal = cryptoContext->MultiAddEvalMultKeys(evalMultKeyFinal, EvalMultKeyAdd[j], EvalMultKeyAdd[j]->GetKeyTag()); 


            std::cout << "EvalSumKey generation started." << std::endl;
            // Generate evalsum key part for first party
            auto evalSumKeys =
                std::make_shared<std::map<usint, EvalKey<DCRTPoly>>>(cryptoContext->GetEvalSumKeyMap(parties[0].kpShard.secretKey->GetKeyTag()));

            std::shared_ptr<std::map<usint, lbcrypto::EvalKey<lbcrypto::DCRTPoly>>> evalSumkKeysJoin;

            for (int i = 1; i < numparties; i++) {
                auto evalSumkKeysPartyi = cryptoContext->MultiEvalSumKeyGen(parties[i].kpShard.secretKey, evalSumKeys, parties[i].kpShard.publicKey->GetKeyTag());
                    evalSumkKeysJoin = cryptoContext->MultiAddEvalSumKeys(evalSumKeys, evalSumkKeysPartyi, parties[i].kpShard.publicKey->GetKeyTag());
                    evalSumkKeysJoin = cryptoContext->MultiAddEvalSumKeys(evalSumkKeysJoin, evalSumkKeysPartyi, parties[i].kpShard.publicKey->GetKeyTag());

@moghit02 Please note that this forum is not designed for checking the code written by users of OpenFHE. If you want to report a specific bug or ask a question on the use of the library, we would be happy to answer it. The current request is outside the scope of the OpenFHE Discourse forum.