[api] move do_branch function into it's own class

500 lines and counting deserve a class ;)