Again maybe move this logic to the top to help simplify this function and remove the extra clauses.