Code for manipulating binary trees