Fixed the BFS-stepwise algorithm to properly clean buffers.