Refactor. DFS also works now (avoid trace back to the boarder).