More robust serialization and use of abstract base class.