function buy(address _address, uint _value, uint _time, bool dashboard) internal returns (bool){
    uint tokensForSend;
    uint etherForSend;
    if (isPreIco(_time)){
      (tokensForSend,etherForSend) = buyIfPreIcoDiscount(_value);
      assert (tokensForSend >= 50*pow(10,decimals));
      preIcoTokensSold += tokensForSend;
      if (etherForSend!=0 && !dashboard){
        _address.transfer(etherForSend);
      }
      owner.transfer(this.balance);
    }
    if (isIco(_time)){
      if(!preIcoEnded){
        for (uint i = 0; i<structurePreIco.length; i++){
          structureIco[structureIco.length-1].balance = structureIco[structureIco.length-1].balance.add(structurePreIco[i].balance);
          structurePreIco[i].balance = 0;
        }
       preIcoEnded = true;
      }
      (tokensForSend,etherForSend) = buyIfIcoDiscount(_value);
      assert (tokensForSend >= 50*pow(10,decimals));
      iCoTokensSold += tokensForSend;

      if (etherForSend!=0 && !dashboard){
        _address.transfer(etherForSend);
      }
      investorBalances[_address] += _value.sub(etherForSend);

      if (isIcoTrue()){
        owner.transfer(this.balance);
      }
    }

    tokensSold += tokensForSend;

    token.sendCrowdsaleBalance(_address,tokensForSend);

    ethCollected = ethCollected.add(_value.sub(etherForSend));

    return true;
  }