Code refactoring in breadth-first.