function buyTokens(
        address user,
        uint256 amount
    ) internal {
        require(amount <= hardFundingGoal.sub(amountRaised));

        uint256 passedSeconds = getTime().sub(started);
        uint256 week = 0;
        if (passedSeconds >= 604800){
            week = passedSeconds.div(604800);
        }
        Debug(week);

        uint256 tokenPrice;
        if (state == State.Ico){
            uint256 cup = amountRaised.mul(4).div(hardFundingGoal);
            if (cup > week)
                week = cup;
            if (week >= 4)
                 week = 3;
            tokenPrice = price.mul(icoTokenPrice[week]).div(100);
        } else {
            if (week >= 2)
                 week = 1;
            tokenPrice = price.mul(preIcoTokenPrice[week]).div(100);
        }

        Debug(tokenPrice);

        uint256 count = amount.div(tokenPrice);
        uint256 discount = getDiscountOf(amount);
        uint256 discountBonus = discount.mul(count).div(100);
        count = count.add(discountBonus);
        count = ceilTokens(count);

        require(tokenReward.transfer(user, count));
        balances[user] = balances[user].add(amount);
        amountRaised = amountRaised.add(amount);
        TokenPurchased(user, amount, count, discountBonus);
    }