Fix attempt for infinite loop in BFS issue