Implementing print_tree function