function buyTokens(address beneficiary) public payable {
    require(token != address(0));
    require(beneficiary != address(0));
    require(validPurchase());

    uint256 weiAmount = msg.value;
    uint256 currentRate = rate;
    uint256 tokens;
    bool inPowerDay = saleInPowerDay();

    
    
    
    if (inPowerDay == true) {
      tokens = weiAmount.mul(powerDayRate);      
    } else {
      tokens = weiAmount.mul(currentRate);      
    }
    
    
    uint256 checkedSupply = token.totalSupply().add(tokens);
    require(willFitInCap(checkedSupply));
    

    if (inPowerDay == true) {
      uint256 newWeiAmountPerSender = powerDayAddressLimits[msg.sender].add(weiAmount);

      
      if (newWeiAmountPerSender > powerDayPerPersonCapInWei()) {
        revert();
      } else {
        powerDayAddressLimits[msg.sender] = newWeiAmountPerSender;
      }
    }

    
    
    token.mint(beneficiary, tokens);

    TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

    forwardFunds();
  }