major refactoring of serialization of metadata