Refactor to use some sub-functions in online-DFS.