Make savehist serialization more robust