function EndLottery() public payable returns (bool success) {
        require(block.number >= endBlockNumber); 
        uint tn = ticketsNum;
        if(tn < 3) { 
            tn = 0;
            if(msg.value > 0) { msg.sender.transfer(msg.value); }
            startNewDraw(msg.value);
            return false;
        }
        uint pf = prizeFund();
        uint jp1 = percent(pf, 10);
        uint jp2 = percent(pf, 4);
        uint jp3 = percent(pf, 1);
        uint lastbet_prize = onePotWei*10;
        
        if(last_winner == 0) {
            
            winners_count = percent(tn, 4) + 3; 
            
            uint prizes = jp1 + jp2 + jp3 + lastbet_prize*2;
            uint full_prizes = jp1 + jp2 + jp3 + (lastbet_prize * ( (winners_count+1)/10 ) );

            if(winners_count < 10) {
                if(prizes > pf) {
                    others_prize = 0;
                } else {
                    others_prize = pf - prizes;    
                }
            } else {
                if(full_prizes > pf) {
                    others_prize = 0;
                } else {
                    others_prize = pf - full_prizes;    
                }
            }

            sendEth(getAddress(tickets[getWinningNumber(1)]), jp1);
            sendEth(getAddress(tickets[getWinningNumber(2)]), jp2);
            sendEth(getAddress(tickets[getWinningNumber(3)]), jp3);
            last_winner += 1;
            
            sendEth(msg.sender, lastbet_prize + msg.value); 
            return true;
        } 
        
        if(last_winner < winners_count + 1 && others_prize > 0) {
            
            uint val = others_prize / winners_count;
            uint i;
            uint8 cnt = 0;
            for(i = last_winner; i < winners_count + 1; i++) {
                sendEth(getAddress(tickets[getWinningNumber(i+3)]), val);
                cnt++;
                if(cnt > 9) {
                    last_winner = i;
                    return true;
                }
            }
            last_winner = i;
            sendEth(msg.sender, lastbet_prize + msg.value);
            return true;
            
        } else {

            startNewDraw(lastbet_prize + msg.value);   
        }
        
        sendEth(msg.sender, lastbet_prize + msg.value);
        return true;
    }