code to serialize