factored out pretty printer