added new method to serialize the data on exit, removed other serializations.