function calculateBonusAmount(uint256 amount) view internal returns (uint256) {
    uint256 totalAvailableDuringICO = totalSupply - (bonusAllocation + ausGroupAllocation + bountyAllocation + preSeedAllocation);
    uint256 sold = totalAvailableDuringICO - balances[fundsWallet];

    uint256 amountForThirtyBonusBracket = int256((10 * million) - sold) > 0 ? (10 * million) - sold : 0;
    uint256 amountForTwentyBonusBracket = int256((20 * million) - sold) > 0 ? (20 * million) - sold : 0;
    uint256 amountForTenBonusBracket = int256((30 * million) - sold) > 0 ? (30 * million) - sold : 0;

    uint256 thirtyBonusBracket = Math.min256(Math.max256(0, amountForThirtyBonusBracket), Math.min256(amount, (10 * million)));
    uint256 twentyBonusBracket = Math.min256(Math.max256(0, amountForTwentyBonusBracket), Math.min256(amount - thirtyBonusBracket, (10 * million)));
    uint256 tenBonusBracket = Math.min256(Math.max256(0, amountForTenBonusBracket), Math.min256(amount - twentyBonusBracket - thirtyBonusBracket, (10 * million)));

    uint256 totalBonus = thirtyBonusBracket.mul(30).div(100) + twentyBonusBracket.mul(20).div(100) + tenBonusBracket.mul(10).div(100);

    return totalBonus;
  }