fix up branch detection code