Finished basic depth-first search