To reduce code nesting and make it easier to see what happens in the error case, perhaps it's better to `if (branchRef == null) throw ...`, and move the main block out of the if-else.