added notExpanded function and specify logic in bfs