Make code more object oriented, corrected building branch tree