factor branch-compat check into function