debugged branching function