factored branch_switch.py some more