Revert get_branches algorithm, simplify compile_regex