Forming DFS trees, refactored tests