added some tree code and fixed another problem