Changing BFS(using arrays) code