definitions and printing tree function