working on dfs method