Is it worth pulling this check out into an inline function call? It's pretty complex.