Rearrange code in GetDefectPayload for readability