core code for pretty printer of new trees