Complete new setup, now using transients and the shutdown hook.