function doInvest(address referrerAddr) public payable notFromContract balanceChanged {
        uint investment = msg.value;
        uint receivedEther = msg.value;
        require(investment >= minInvesment, "investment must be >= minInvesment");
        require(address(this).balance <= maxBalance, "the contract eth balance limit");

        if (m_rgp.isActive()) {
        
            uint rpgMaxInvest = m_rgp.maxInvestmentAtNow();
            rpgMaxInvest.requireNotZero();
            investment = Math.min(investment, rpgMaxInvest);
            assert(m_rgp.saveInvestment(investment));

      } 

      
        if (receivedEther > investment) {
            uint excess = receivedEther - investment;
            msg.sender.transfer(excess);
            receivedEther = investment;
      }

      
        advertisingAddress.transfer(m_advertisingPercent.mul(receivedEther));
        adminsAddress.transfer(m_adminsPercent.mul(receivedEther));
        riskAddress.transfer(m_riskPercent.mul(receivedEther));

        bool senderIsInvestor = m_investors.isInvestor(msg.sender);

      
        if (referrerAddr.notZero() && !senderIsInvestor && !m_referrals[msg.sender] &&
            referrerAddr != msg.sender && m_investors.isInvestor(referrerAddr)) {

            m_referrals[msg.sender] = true;
            
            uint refBonus = refBonusPercent().mmul(investment);
            
            uint refBonuss = refBonusPercentt().mmul(investment);
            
            investment += refBonuss;
            
            referrerAddr.transfer(refBonus);                                    
            
        }

      
        uint dividends = calcDividends(msg.sender);
        if (senderIsInvestor && dividends.notZero()) {
            investment += dividends;
        }

        if (senderIsInvestor) {
                
            assert(m_investors.addInvestment(msg.sender, investment, dividends));
            assert(m_investors.setPaymentTime(msg.sender, now));
        } else {
            
            assert(m_investors.newInvestor(msg.sender, investment, now));
        }

        investmentsNumber++;
    }