Minor style point, but I'd prefer to put this global check before the call to this function instead of inside, I think it reads a little better, and it skips the function call (even though there's no measurable performance difference here, it's possible in other cases that there might be some heavy operation inside a function)