fixed some bugs and improved the pretty printing.