added serialization method and saving serialized object