tree class implementation