function purchaseCity(uint256 _tokenId) public 
    payable
    isNotContract(msg.sender)
  {

    
    City storage city = cityData[_tokenId];
    uint256 price = city.price;
    address oldOwner = city.owner;
    address newOwner = msg.sender;

    
    require(price > 0);
    require(msg.value >= price);
    require(oldOwner != msg.sender);

    uint256 excess = msg.value.sub(price);

    
    uint256 profit = price.sub(city.lastPrice);
    uint256 poolCut = calculatePoolCut(profit);
    poolTotal += poolCut;

    
    uint256 devCut = price.mul(3).div(100);
    devOwed = devOwed.add(devCut);

    transferCity(oldOwner, newOwner, _tokenId);

    
    city.lastPrice = price;
    city.price = getNextPrice(price);

    
    CityPurchased(_tokenId, newOwner, price);

    
    oldOwner.transfer(price.sub(devCut.add(poolCut)));

    
    uint256 countryId = _tokenId % COUNTRY_IDX;
    address countryOwner;
    (countryOwner,,,,) = countryContract.getCountryData(countryId);
    require (countryOwner != address(0));
    countryOwner.transfer(poolCut.mul(COUNTRY_PAYOUT).div(100));

    
    if (excess > 0) {
      newOwner.transfer(excess);
    }

    
    lastPurchase = now;

  }