function doInvest() internal {
        uint256 investment = msg.value;
        require (investment >= MINIMUM_DEPOSIT);
        
        User storage user = users[wave][msg.sender];
        if (user.firstTime == 0) {
            user.firstTime = now;
            user.lastPayment = now;
            emit InvestorAdded(msg.sender);
        }

        
        if (user.referrer == address(0) && msg.data.length == 20 && user.firstTime == now) {
            address newReferrer = _bytesToAddress(msg.data);
            if (newReferrer != address(0) && newReferrer != msg.sender && users[wave][newReferrer].firstTime > 0) {
                user.referrer = newReferrer;
                emit ReferrerAdded(msg.sender, newReferrer);
            }
        }
        
        
        if (user.referrer != address(0)) {
            uint256 refAmount = investment.mul(referralPercents).div(ONE_HUNDRED_PERCENTS);
            users[wave][user.referrer].referralAmount = users[wave][user.referrer].referralAmount.add(investment);
            users[wave][user.referrer].referBonus = users[wave][user.referrer].referBonus.add(refAmount);
        }
        
        
        investment = investment.add(getDividends(msg.sender));
        
        
        user.deposits.push(Deposit({
            amount: investment,
            interest: getUserInterest(msg.sender),
            withdrawedRate: 0
        }));
        emit DepositAdded(msg.sender, user.deposits.length, investment);

        
        uint256 marketingAndTeamFee = msg.value.mul(MARKETING_AND_TEAM_FEE).div(ONE_HUNDRED_PERCENTS);
        marketingAndTeam.transfer(marketingAndTeamFee);
        emit FeePayed(msg.sender, marketingAndTeamFee);
    
        emit BalanceChanged(address(this).balance);
    }