Performance imporved by Church-encoded free monads.