Add back the missing ToJSON and FromJSON instances.
Replace some monadic code with equivalent functorial versions.
Small readability refactoring.