added BFS algorithm