Convert to a real A* Search algorithm instead of a thrown together hack
formed by a combination of A* and Depth-First searches.

This ensures that any path found will always be the shortest possible
path. In the previous version longer chains became incredibly likely to
contain useless cycles due to an implementation failing in backtracking.