small modification of dfs