modified isbranchvalid()
modified isBranchValid()