Added tree function and replaced basestring with str