adjusted DFS to use correct direction