added logs and fixed bfs