Serializing data in each iteration