This check has appeared three times in this one file. Should definitely pull it out into a separate function.