Factoring serialize operation