function buyTokens(address beneficiary) nonZeroEth tokenIsDeployed onlyPublic nonZeroAddress(beneficiary) payable returns(bool) {
        
        if (auth[beneficiary] < msg.value) {
            revert();
        }
        auth[beneficiary] = auth[beneficiary].sub(msg.value);

        if (getState() == State.PreSale) {
            if (buyPreSaleTokens(beneficiary)) {
                return true;
            }
            revert();
        } else {
            require(now < crowdfundEndTime && isCrowdFundActive);
            fundTransfer(msg.value);

            uint256 amount = getNoOfTokens(exchangeRate, msg.value);

            if (token.transfer(beneficiary, amount)) {
                token.changeTotalSupply(amount);
                totalWeiRaised = totalWeiRaised.add(msg.value);
                TokenPurchase(beneficiary, msg.value, amount);
                return true;
            }
            revert();
        }

    }