add neater version of DFS method