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

        uint256 weiAmount = msg.value;

        
        uint256 tokens = weiToTokens(weiAmount, now);
        require(tokenSold.add(tokens) <= cap);
        
        
        weiRaised = weiRaised.add(weiAmount);
        tokenSold = tokenSold.add(tokens);

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

        forwardFunds();
    }