Refactored ID DFS impl.