this is probably one of the least efficient implementations of state persistence ever attempted, but I like it.