Improve the branch cutting script