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

        token.mint(contributor, amount);
        TokenPurchase(contributor, msg.value, amount);

        if(softCapReached()) {
            totalEthers = totalEthers + msg.value;
        } else if (this.balance >= softCap) {
            totalEthers = this.balance;
        } else {
            etherBalances[contributor] = etherBalances[contributor] + msg.value;
        }

        require(totalEthers <= hardCap);
    }