implementing dynamic tree generation