various imporovements and some refactoring on pretty printer