Don't hold on to potentially large states, using WeakReferences.
Various cleanups