fixing bug in BFS single-threaded