made lots of changes, added recursive tree generate function