Hmm, to move this out: there's not much else going on in this function. Even if this were moved to a helper function, it would still remain as this nested set of if checks. I'm open to ideas on how to make it cleaner.