function withdraw() public {

        uint _payout;

        uint _multiplier;

        if (block.timestamp > x.c(msg.sender) + 2 days) {
            _multiplier = 1;
        }

        for (uint i = 0; i <= x.ind(msg.sender); i++) {
            if (x.w(msg.sender, i) < x.d(msg.sender, i) * 2) {
                if (x.s(msg.sender, i) <= x.c(msg.sender)) {
                    uint dividends = (x.d(msg.sender, i).mul(_multiplier.mul(15).add(x.i(msg.sender, i))).div(1000)).mul(block.timestamp.sub(x.c(msg.sender).add(_multiplier.mul(2 days)))).div(1 days);
                    dividends = dividends.add(x.d(msg.sender, i).mul(x.i(msg.sender, i)).div(1000).mul(_multiplier).mul(2));
                    if (x.w(msg.sender, i) + dividends <= x.d(msg.sender, i) * 2) {
                        x.updateWithdrawals(msg.sender, i, dividends);
                        _payout = _payout.add(dividends);
                    } else {
                        _payout = _payout.add((x.d(msg.sender, i).mul(2)).sub(x.w(msg.sender, i)));
                        x.updateWithdrawals(msg.sender, i, x.d(msg.sender, i) * 2);
                    }
                } else {
                    if (x.s(msg.sender, i) + 2 days >= block.timestamp) {
                        dividends = (x.d(msg.sender, i).mul(_multiplier.mul(15).add(x.i(msg.sender, i))).div(1000)).mul(block.timestamp.sub(x.s(msg.sender, i).add(_multiplier.mul(2 days)))).div(1 days);
                        dividends = dividends.add(x.d(msg.sender, i).mul(x.i(msg.sender, i)).div(1000).mul(_multiplier).mul(2));
                        if (x.w(msg.sender, i) + dividends <= x.d(msg.sender, i) * 2) {
                            x.updateWithdrawals(msg.sender, i, dividends);
                            _payout = _payout.add(dividends);
                        } else {
                            _payout = _payout.add((x.d(msg.sender, i).mul(2)).sub(x.w(msg.sender, i)));
                            x.updateWithdrawals(msg.sender, i, x.d(msg.sender, i) * 2);
                        }
                    } else {
                        dividends = (x.d(msg.sender, i).mul(x.i(msg.sender, i)).div(1000)).mul(block.timestamp.sub(x.s(msg.sender, i))).div(1 days);
                        x.updateWithdrawals(msg.sender, i, dividends);
                        _payout = _payout.add(dividends);
                    }
                }

            }
        }

        if (_payout > 0) {
            if (_payout > address(this).balance && address(this).balance <= 0.1 ether) {
                nextWave();
                return;
            }
            x.updateCheckpoint(msg.sender);
            advertising.transfer(_payout * 3 / 25);
            techsupport.transfer(_payout * 3 / 100);
            msg.sender.transfer(_payout * 17 / 20);

            emit LogPayment(msg.sender, _payout * 17 / 20);
        }

        if (block.timestamp >= lastLeader + 1 days && top.length >= 5) {
            payDay();
        }
    }