while (succItr.hasNext()) {
State succ = (State) succItr.next(); // next successor
if (needToVisit(succ)) {
if (succ.goalReached()) { // if we've found a goal state - return it as the solution
return succ;
} else if (succ.getHValue().compareTo(bestHValue) < 0) {
// if we've found a state with a better heuristic value than the best seen so far
bestHValue = succ.getHValue(); // note the new best avlue