slightly refactoring serialization