Refactor branch chooser a bit and add some specs