By factoring out this logic, it's easier for other projects to make use of it this optimization too (and do it correctly).