implemented dfs