fix direction bug on dfs