function buyTokens(address beneficiary) public payable {
    transStartTime=now;
    require(goldList[beneficiary]||kycAcceptedList[beneficiary]);
    goldListPeriodFlag=false;
	require(beneficiary != address(0));
    require(validPurchase());
    uint256 extraEth=0;
    weiAmount = msg.value;
   
    
    
    if((msg.value>ethCap.sub(mainWeiRaised)) && !goldListPeriodFlag){
		weiAmount=ethCap.sub(mainWeiRaised);
		extraEth=(msg.value).sub(weiAmount);
	 }
	 
    
     tokens = getTokenAmount(weiAmount);
   
    
    mainWeiRaised = mainWeiRaised.add(weiAmount);
    token.mint(beneficiary, tokens);
	mainContribution[beneficiary] = mainContribution[beneficiary].add(weiAmount);
	if(goldListPeriodFlag){
	    goldListContribution[beneficiary] = goldListContribution[beneficiary].add(weiAmount);
	}
	
    
    TokenPurchase(beneficiary, weiAmount, tokens);

    forwardFunds();
    if(extraEth>0){
        beneficiary.transfer(extraEth);
    }
    
 
  }