The process of iterating over all cage atoms within the threshold distance is sped up by using the SciPy Spatial KDTree algorithm, which partitions multidimensional data into a binary tree structure, enabling efficient nearest-neighbor searches and spatial queries. To achieve this, the cartesian positions of all cage atoms are stored in a KDTree dictionary by atom types, significantly reducing the time required for obtaining atoms within a threshold distance compared to brute-force iteration. Once the iteration over all grid points in the grid is completed, and all grid points are assigned as within or outside the cavity, C3 uses a DBSCAN clustering algorithm to identify the main cavity region, disregarding isolated grid points that do not correspond to the cavity. In cases where more than one cavity is identified, the main cavity is selected based on the largest cluster, or alternatively, the cluster closest to the cage center of mass.