    function calculateTokens(uint value) internal view returns (uint256 tokens) 
    {
        uint256 timeElapsed = now - startTime;
        uint256 timeElapsedInDays = timeElapsed.div(1 days);
        uint256 bonus = 0;
        if (timeElapsedInDays <15)
        {
            tokens = value.mul(ratePerWei);
            bonus = tokens.mul(bonusInPhase1); 
            bonus = bonus.div(100);
            tokens = tokens.add(bonus);
            require (TOKENS_SOLD.add(tokens) <= maxTokensToSale);
        }
        else if (timeElapsedInDays >=15 && timeElapsedInDays <30)
        {
            tokens = value.mul(ratePerWei);
            bonus = tokens.mul(bonusInPhase2); 
            bonus = bonus.div(100);
            tokens = tokens.add(bonus);
            require (TOKENS_SOLD.add(tokens) <= maxTokensToSale);
        }
        else 
        {
            bonus = 0;
        }
    }