optimization in CountRectangle