refactoring of how get ref for a head branch...