Handle undefin in dfs