finally got branching correct, was getting so confused, it's late :(