Added boundary checks for KK_MaskStarts / KK_MinMaxClusters