function buyTokens(address contributor) payable stopInEmergency validPurchase public {
        uint256 amount;
        uint256 odd_ethers;
        uint256 ethers;
        
        (amount, odd_ethers) = calcAmountAt(msg.value, block.timestamp, token.totalSupply());
  
        require(contributor != 0x0) ;
        require(amount + token.totalSupply() <= mintCapInTokens);

        ethers = (msg.value - odd_ethers);

        token.mint(contributor, amount); 
        TokenPurchase(contributor, ethers, amount);
        totalETH += ethers;

        if(odd_ethers > 0) {
            require(odd_ethers < msg.value);
            TransferOddEther(contributor, odd_ethers);
            contributor.transfer(odd_ethers);
        }

        wallet.transfer(ethers);
    }