Fix a bug in serialize