Factorize culling code.