Replacing ListBuffer with proper Queue in BFS method.