Variation of BFS