Attempt at a DFS like algorithm