How to add pending balance of address in solidity?

This contract is betting:https://testnet.bscscan.com/address/0xD6fDB5bB014b593fdb6793D6ce07403698e404eA#code

The problem is when the prize is allocated to those winners for claim, the allocation is double upon allocating prizes.

Code for allocating prize:

// Generates a number between 1 and 10 that will be the winner
    function allocatePrizes(uint _gameId, uint16 teamWinner) public onlyAgent {
        Game storage game = gameInfo[_gameId];
        require(bettingActive == false);
        address[1000] memory winners;
        address[1000] memory draw;
        //We have to create a temporary in memory array with fixed size
        //Let's choose 1000
       
        uint256 LoserBet = 0; //This will take the value of all losers bet
        uint256 WinnerBet = 0; //This will take the value of all winners bet
        

        //We loop through the player array to check who selected the winner team
        for(uint256 i = 0; i < players.length; i++){
            address playerAddress = players[i];
            //If the player selected the winner team
            //We add his address to the winners array
            if(playerInfo[playerAddress].teamSelected == teamWinner){
                winners[count] = playerAddress;
                count++;
            }
            playerInfo[playerAddress]._state = PlayerStatus.Not_Joined;
        }


        //We define which bet sum is the Loser one and which one is the winner
        if ( teamWinner == 1){
            LoserBet = totalBetsTwo;
            WinnerBet = totalBetsOne;
        //We loop through the array of winners, to give ethers to the winners
        for(uint256 j = 0; j < count; j++){
            // Check that the address in this fixed array is not empty
            if(winners[j] != address(0)){
             add = winners[j];
             bets = playerInfo[add].amountBet;

            // token.transfer(winners[j],  (bets*(10000+(LoserBet*fee /WinnerBet)))/10000 );
             rewards = (bets*(10000+(LoserBet*fee /WinnerBet)))/10000;
            _pendingBalance[add] += rewards;
            }
           
        }
        gameInfo[_gameId] = Game(_gameId, State.Finished);
        game.state == State.Finished;
        // playerInfo[playerAddress]._state = PlayerStatus.Not_Joined;
        delete playerInfo[playerAddress]; // Delete all the players
        players.length = 0; // Delete all the players array
        LoserBet = 0; //reinitialize the bets
        WinnerBet = 0;
        totalBetsOne = 0;
        totalBetsTwo = 0;
            
        }
        else if(teamWinner == 2){
            LoserBet = totalBetsOne;
            WinnerBet = totalBetsTwo;
        //We loop through the array of winners, to give ethers to the winners
        for(uint256 k = 0; k < count; k++){

            // Check that the address in this fixed array is not empty
            if(winners[k] != address(0)){
             add = winners[k];
             bets = playerInfo[add].amountBet;

            // token.transfer(winners[k],  (bets*(10000+(LoserBet*fee /WinnerBet)))/10000 );
            rewards = (bets*(10000+(LoserBet*fee /WinnerBet)))/10000;
            _pendingBalance[add] += rewards;
            }
        }
        gameInfo[_gameId] = Game(_gameId, State.Finished);
        game.state == State.Finished;
        // playerInfo[playerAddress]._state = PlayerStatus.Not_Joined;
        delete playerInfo[playerAddress]; // Delete all the players
        players.length = 0; // Delete all the players array
        LoserBet = 0; //reinitialize the bets
        WinnerBet = 0;
        totalBetsOne = 0;
        totalBetsTwo = 0;
                
        }
        else if(teamWinner == 3){
            //We loop through the player array to check who selected the winner team
        
        for(uint256 l = 0; l < players.length; l++){
            add = players[l];

            if(playerInfo[add].teamSelected == 1||playerInfo[add].teamSelected == 2){
                draw[num] = add;
                num++;
            }
        }
        //We loop through the array of winners, to give ethers to the winners
        for(uint256 m = 0; m < num; m++){
            // Check that the address in this fixed array is not empty
            if(draw[m] != address(0)){
             add = draw[m];
             bets = playerInfo[add].amountBet;

            // token.transfer(draw[m], (bets*(fee))/10000 );
            
            rewards = (bets*(fee))/10000;
            _pendingBalance[add] += rewards;
        }
        gameInfo[_gameId] = Game(_gameId, State.Finished);
        game.state == State.Finished;
        playerInfo[add]._state = PlayerStatus.Not_Joined;
        delete playerInfo[add]; // Delete all the players
        players.length = 0; // Delete all the players array
        LoserBet = 0; //reinitialize the bets
        WinnerBet = 0;
        totalBetsOne = 0;
        totalBetsTwo = 0;
        }
       
    }
       
    }

and the claim function:

function balanceOf(address user) public constant returns (uint256) {
    uint256 levs = _pendingBalance[user];
    return levs;
    }

    function claimRewards()  public {
    uint256 balance = balanceOf(msg.sender);
    require(balance > 0);
    _pendingBalance[msg.sender] = 0;
    token.transfer(msg.sender, balance);
    emit ClaimRewards(msg.sender, balance);
  }