Factorize culling code