private StateDist limitDfs(SearchState oldState, int curDist, int maxDist) {
    int estimatedCost = curDist + h.estimateCostToGoal(oldState);
    if (estimatedCost > maxDist) {
      if (estimatedCost >= OO)
        return null;
      Integer dist = statesWithUnexploredNodes.get(oldState.prevState);
      int prevDist = stateDistMap.get(oldState.prevState);
      if (dist == null || dist > prevDist) {
        if (dist != null)
          statesWithUnexploredNodes.remove(oldState.prevState);
        statesWithUnexploredNodes.put(oldState.prevState, prevDist);
      }
      return new StateDist(null, estimatedCost);

    }

    Integer dist = stateDistMap.get(oldState);
    if (dist != null && dist <= curDist)
      return null;
    stateDistMap.put(oldState, curDist);

    if (oldState.rowsToGo <= 0)
      return new StateDist(oldState, curDist);

    return expandChildren(oldState, curDist);
  }