function settleBet(uint reveal, uint cleanCommit) external {
        
        uint commit = uint(keccak256(abi.encodePacked(reveal)));

        
        Bet storage bet = bets[commit];
        uint amount = bet.amount;
        uint modulo = bet.modulo;
        uint rollUnder = bet.rollUnder;
        uint placeBlockNumber = bet.placeBlockNumber;
        address gambler = bet.gambler;

        
        require (amount != 0, "Bet should be in an 'active' state");

        
        require (block.number > placeBlockNumber, "settleBet in the same block as placeBet, or before.");
        require (block.number <= placeBlockNumber + BET_EXPIRATION_BLOCKS, "Blockhash can't be queried by EVM.");

        
        bet.amount = 0;

        
        
        
        
        bytes32 entropy = keccak256(abi.encodePacked(reveal, blockhash(placeBlockNumber)));

        
        uint dice = uint(entropy) % modulo;
        uint diceWinAmount = getDiceWinAmount(amount, modulo, rollUnder);

        uint diceWin = 0;
        uint jackpotWin = 0;

        
        if (modulo <= MAX_MASK_MODULO) {
            
            if ((2 ** dice) & bet.mask != 0) {
                diceWin = diceWinAmount;
            }

        } else {
            
            if (dice < rollUnder) {
                diceWin = diceWinAmount;
            }

        }

        
        lockedInBets -= uint128(diceWinAmount);

        
        if (amount >= MIN_JACKPOT_BET) {
            
            
            uint jackpotRng = (uint(entropy) / modulo) % JACKPOT_MODULO;

            
            if (jackpotRng == 0) {
                jackpotWin = jackpotSize;
                jackpotSize = 0;
            }
        }

        
        uint totalWin = diceWin + jackpotWin;

        if (totalWin == 0) {
            totalWin = 1 wei;
        }

        
        if (jackpotWin > 0) {
            emit JackpotPayment(gambler, jackpotWin);
        }

        
        sendFunds(gambler, totalWin, diceWin);

        
        if (cleanCommit == 0) {
            return;
        }

        clearProcessedBet(cleanCommit);
    }