Fix logic for discovering new branches