Better error handling, and fixes for pretty printing.