fix branch_counter; debug output
fix iteration order