Wrap branch merging method with additional error checks