refactor branch iterator