Move serialization logic to utils