Optimized count-only qurty building.