fully functional tree generation