Implemented recursive dfs