cleaned up the code on createBranch function