bfs for not letting it close, input errors