Replaced breadth-first tree search with best-first