Fix bug in PrettyPrinter, add roundtrip and idempotency tests