Replace stateful history with (almost) functional equivalent. Not quite purely functional to retain the ability to interact with the demo from the repl.