fixed addBranch function