Added thread termination cleanup for DFS