DRY up code to check if a field is a group
Fix logic mixup
Add error handling for invalid usage of serialize_data