refactor serialize