fixed dfs errors and depth calculation