Add tree triming function