Fix output format.
Replace PrettyLambda with ReprWrapper.
Split a big chunk of code from __main__ into two separate functions.