add check condition for DFS search