Move code to clean up after a branch change to branch.c