function buyTokens(address _beneficiary) public payable {
        uint256 weiAmount = msg.value;
        require(_beneficiary != address(0));
        require(weiAmount != 0);
        require(block.timestamp >= startTime && block.timestamp <= endTime);
        uint256 tokens = weiAmount.div(rate);
        require(tokens != 0 && sold.add(tokens) <= cap);
        sold = sold.add(tokens);
        require(token.transfer(_beneficiary, tokens));
        emit TokenPurchase(
            msg.sender,
            _beneficiary,
            weiAmount,
            tokens
        );
    }