Added BFS function and etc.