public static void teleportPlayerBack(EntityPlayerMP player) {
    NBTTagCompound playerNBT = player.getEntityData();
    if (playerNBT.hasKey("coordHistory")) {
      NBTTagList coordHistory = playerNBT.getTagList("coordHistory", 10);
      if (coordHistory.tagCount() == 0) {
        // No coord history so far, teleport back to overworld
        TeleportTools.teleportPlayerOutOfMachineDimension(player);
      } else {
        // Remove the last tag, then teleport to the new last
        coordHistory.removeTag(coordHistory.tagCount() - 1);
        if (coordHistory.tagCount() == 0) {
          TeleportTools.teleportPlayerOutOfMachineDimension(player);
          return;
        }

        int coord = coordHistory.getCompoundTagAt(coordHistory.tagCount() - 1).getInteger("coord");
        TeleportTools.teleportPlayerToCoords(player, coord, true);
      }
    } else {
      // No coord history on the player yet - teleport him out of there.
      TeleportTools.teleportPlayerOutOfMachineDimension(player);
    }
  }