tidy up branch handling