Fixed inf loop in branch and junction join code