code optimization for deliverycount