add dfs logic, bug fix