Refactor prettyPrinter to work with immutable objects

[#50766813][#266]