branch selection - refactor and improvement