refactored branch update function