Because the last return of casetracker_case_state_save is an unset variable, it will always return null. Suggest that instead the function returns the recently saved/updated state record.