recursion and skip unnecessary search, kind of like dfs