refactoring serialize